ASPX templates
Version 7.x > ASPX templates > Poll percentage not adding up to 100%! View modes: 
User avatar
Certified Developer v7
Certified  Developer v7
adam - 7/4/2013 11:34:00 AM
   
Poll percentage not adding up to 100%!
Hi i'm using kentico version 7 and when i set a poll up to use percentages they do not add up to 100%! is there a reason for this or a fix?

cheers

User avatar
Kentico Customer Success
Kentico Customer Success
kentico_martind2 - 7/4/2013 12:29:17 PM
   
RE:Poll percentage not adding up to 100%!
Hello Adam,

Could you please tell me what is the sum of all poll parts/percentages?

Best Regards,
Martin Danko

User avatar
Certified Developer v7
Certified  Developer v7
adam - 7/10/2013 5:13:49 AM
   
RE:Poll percentage not adding up to 100%!
hi

it does it on a variety of all poll parts. looking at the code it appears that it rounds the percentage down which kind of makes sense.

e.g yes = 68% no = 31% total 99%

is there a way of getting it to be 100% all the time?

User avatar
Certified Developer v7
Certified  Developer v7
adam - 7/10/2013 8:39:23 AM
   
RE:Poll percentage not adding up to 100%!
ok i've done it.

i think this makes more sense then rounding down.

around line 812 of pollview.ascs.cs

change long percent = 0; to double percent = 0;

then change

percent = Math.BigMul(100, currentValue) / countSummary;
to
percent = Math.Round((double)(currentValue * 100) / countSummary, 1);

this will display the full percentage value so all percentages will equal 100% and never 99%.

cheers

User avatar
Member
Member
kentico_sandroj - 7/10/2013 9:13:49 PM
   
RE:Poll percentage not adding up to 100%!
Adam,

Thank you for sharing this solution - we will make a note of it in case the issue comes up again.

Thanks!
-Sandro

User avatar
Kentico Customer Success
Kentico Customer Success
kentico_martind2 - 7/11/2013 5:33:05 PM
   
RE:Poll percentage not adding up to 100%!
Hello Adam,
This is currently a default behavior caused by rounding result value as we do not want to display percentage value with decimal places and here is the solution I've gone through with one of our customers in the past...

You can change this behavior in the following file: ~\CMSModules\Polls\Controls\PollView.ascx.cs.
As a result, numbers should be displayed with two decimal places (55.32%, 32.49% etc).
Please find the CreateGraph method and change the following code
ORIGINAL CODE:
else if (this.CountType == CountTypeEnum.Percentage)
{
// Percentage count
long percent = 0;
if (countSummary != 0)
{
percent = Math.BigMul(100, currentValue) / (long)countSummary;
}
pnlAnswer.Controls.Add(new LiteralControl(percent.ToString() + "%"));
}

NEW CODE:
else if (this.CountType == CountTypeEnum.Percentage)
{
// Percentage count
float percent = 0;
if (countSummary != 0)
{
percent = (float)Math.BigMul(100, currentValue) / (float)countSummary;
}
pnlAnswer.Controls.Add(new LiteralControl(percent.ToString("f2") + "%"));
}

Best Regards,
Martin Danko