Polls percentage accounting is not accurate

poll

(Dmitry Lomakin) #1

It seems when calculating percentage for each option in polls Discourse uses floats truncating instead of rounding. This can result into inaccurate percentage values. For instance, a poll with 2 options, 11 voters and votes spread as 5 for the 1st option and 6 for the 2nd option indicates 45% and 54% which is 99% in total but should be 100%.

The math looks to be the following:

  • 100/11*5 is 45.45, which rounded to 0 decimal places is 45, and also truncated to 0 decimal places is 45.
  • 100/11*6 is 54.54, which rounded to 0 decimal places would be 55, but truncated to 0 decimal places is 54.

Would be correct to indicate 55% instead of 54%, it would give the correct total value.


Can someone explain me the math behind polls?
Rounding of percentages on polls is inaccurate
(Régis Hanol) #2

Just pushed a fix :poultry_leg:


(Régis Hanol) #3

This topic was automatically closed after 12 hours. New replies are no longer allowed.