Closed (fixed)
Project:
Advanced Poll
Version:
7.x-3.x-dev
Component:
Code
Priority:
Major
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
1 Oct 2012 at 06:15 UTC
Updated:
28 May 2015 at 23:54 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
ITMonkey commentedround() wouldn't work either and you don't want the percentages to be forced to equal 100% as it can skew the true result. If a vote has three possible answers and each receives the same number of votes, the candidates will all have 33.3(r)% and to force one of them to show 33.4 would indicate a winner when in fact there is none.
Marked priority as minor as the choice of which to use, floor() or round(), is actually personal preference. It may make more sense to include some documentation as to how and where to change the code rather than alter the existing code.
Comment #2
ITMonkey commentedCurrently the code is in advpoll\advpoll_ranking\advpoll_ranking.module at line 621
$percentage = round($rows[0]['votes'] / count($voters) * 100, 1);
and advpoll\includes\advpoll_voteapi.inc at line 165
$percentage = floor((int) $value / (int) $total * 100);
Regardless of which is preferred, should they not be consistent?
Comment #3
nlisgo commentedHere is a proposed batch which allows you to set a value in the variable table to amend the precision. There is no central admin screen for this module but at least this presents an opportunity to set the precision.
So if you have 9 votes and 3 choices (A - 2 votes, B - 3 votes and C - 4 votes).
Currently you would see:
A - 22%
B - 33%
C - 44%
Total 99%
If you set the variable 'advpoll_percentage_precision' to 1 then you would see:
A - 22.2%
B - 33.3%
C - 44.4%
Comment #4
nlisgo commentedAddressed indentation:
Comment #5
soulston commentedSince you are working to whatever number of decimals in $precision, we should show this in the output.
Comment #6
nlisgo commentedI completely agree with the addition to the patch in #5.
Comment #6.0
nlisgo commentedupdated with issue summary template
Comment #7
tripper54 commentedRegardless of the proposed precision patch, I think floor() should be changed to round() in advpoll_calculate_percentage().
I know it won't fix a 3 option, 1/3 each scenario, but it would make a two option vote add up to 100, which I would have thought is a very common use case.
Comment #8
tripper54 commentedNew patch:
* Lets the site admin decide which rounding method to use - 'round' or 'floor'. Defaults to 'round'. This method is used in the two places mentioned in comment #2.
* Adds a configuration form for the module where you can set precision and rounding method.
Sorry there's a bit of noise in the patch. My IDE must've done some auto converting of line breaks to unix format.
Comment #9
tripper54 commentedCommitted.