Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Topic started by: Ben_S on June 03, 2004, 08:39:53 AM

Title: Poll results percentages
Post by: Ben_S on June 03, 2004, 08:39:53 AM
The results of poll votes dont seem to add upto 100%. A poll running on my board has just been mentioned on the radio, they also saw fit to mention that the results added up to 103%.
Title: Re: Poll results percentages
Post by: Daniel D. on June 03, 2004, 08:42:00 AM
That's a known problem since YaBB Gold ??? or SE. If I remember right, the reason are the rounded numbers.
Title: Re: Poll results percentages
Post by: Christian Land on June 03, 2004, 09:02:26 AM
Try what happens if you replace:

'percent' => round($bar, $precision),

with

'percent' => round(($option[1] * 100) / $divisor, $precision),

in Display.php
Title: Re: Poll results percentages
Post by: Ben_S on June 03, 2004, 09:06:34 AM
Quote from: Daniel D. on June 03, 2004, 08:42:00 AM
That's a known problem since YaBB Gold ??? or SE. If I remember right, the reason are the rounded numbers.

Aye, certainly been there a while, just thought it was funny hearing it on the radio.

Quote from: SnowCrash on June 03, 2004, 09:02:26 AM
Try what happens if you replace:
<>

Will try it when I finnish work.
Title: Re: Poll results percentages
Post by: Ben_S on June 03, 2004, 12:31:45 PM
Quote from: SnowCrash on June 03, 2004, 09:02:26 AM
Try what happens if you replace:

'percent' => round($bar, $precision),

with

'percent' => round(($option[1] * 100) / $divisor, $precision),

in Display.php

That fixes it :).
Title: Re: Poll results percentages
Post by: Christian Land on June 03, 2004, 01:15:06 PM
Fine ;D
Title: Re: Poll results percentages
Post by: [Unknown] on June 04, 2004, 06:23:55 AM
 ! The percentages for a poll now add up a little better.

(I changed a different part, but basically the same way.)

-[Unknown]
Title: Re: Poll results percentages
Post by: Skoen on June 04, 2004, 11:33:24 AM
Noticed that too. In a poll where there are 24 votes in it, the total percent is 97% instead 100%. Might try the fix myself, and that made the total to be 99,9% :P
Title: Re: Poll results percentages
Post by: Christian Land on June 04, 2004, 03:09:34 PM
The problem is, that there will always be situations where you won't get a correct result....

But with the fix, the difference to 100% will be smaller.... so i guess its OK... ;D
Title: Re: Poll results percentages
Post by: Springer on June 04, 2004, 03:50:59 PM
How far does it carry a number before it rounds?
Title: Re: Poll results percentages
Post by: Christian Land on June 05, 2004, 02:37:16 AM
Quote from: Springer on June 04, 2004, 03:50:59 PM
How far does it carry a number before it rounds?

The round function (http://de3.php.net/manual/en/function.round.php) only uses a precision of 1... so all numbers get rounded at the first digit after the decimal point. I tested the above fix a little bit, and all my tests gave results between 99,9% and 100%... and it really doesn't matter with what precision the values get rounded... there are situations where the percentages are always false...

for example: 3 people vote for 3 different options... you will always end up with wrong numbers... the current beta of SMF displays 33% for each option... the fixed version will show 33,3%.... even if you change the precision to 1000, you'll still get the same result.... so who cares?