Change the Poll percentage rounding (display decimals)

   —   
In some specific scenarios the SUM of the poll percentages is not 100%.  This is due to the default rounding set and only integer numbers are displayed.
26 + 69 + 3 = 98%

 

This is currently the default behavior caused by a rounding result value as we do not want to display the percentage value with decimals.  However, 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 (changes are marked as green):

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") + "%")); }

-md-


Applies to: Kentico CMS 7.x
Share this article on   LinkedIn

Martin Danko

Let me guide you on your journey of success. I will show you how to optimize your content production with Kentico Draft. Check out www.kenticocloud.com