# Polls percentage accounting is not accurate

**URL:** https://meta.discourse.org/t/polls-percentage-accounting-is-not-accurate/35772
**Category:** Bug
**Tags:** polls
**Created:** [18 نوفمبر 2015، 9:19م UTC](https://meta.discourse.org/t/polls-percentage-accounting-is-not-accurate/35772 "2015-11-18T21:19:03Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Dmitry\_Lomakin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dmitry_lomakin/32/122094_2.png) [@Dmitry\_Lomakin](https://meta.discourse.org/u/Dmitry_Lomakin)
#### Post date: [18 نوفمبر 2015، 9:19م UTC](https://meta.discourse.org/t/polls-percentage-accounting-is-not-accurate/35772/1 "2015-11-18T21:19:03Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [19 نوفمبر 2015، 5:24م UTC](https://meta.discourse.org/t/polls-percentage-accounting-is-not-accurate/35772/2 "2015-11-19T17:24:00Z")

</div>

Just pushed a fix 🍗

[https://github.com/discourse/discourse/commit/32b6ccd6227e561d5ac8f5443e766344402a946b](https://github.com/discourse/discourse/commit/32b6ccd6227e561d5ac8f5443e766344402a946b)

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [20 نوفمبر 2015، 5:24ص UTC](https://meta.discourse.org/t/polls-percentage-accounting-is-not-accurate/35772/3 "2015-11-20T05:24:23Z")

</div>

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