You can see the difference between this and blindly rounding each value, in the third value above. The 'correct' rounded values are in the final column and you can see that they sum to 100. This works because you're not losing information at each stage but rather using the information more intelligently. Instead, you round the accumulated value and work out the best integer that reaches that value from the previous baseline - that baseline is the cumulative value (rounded) of the previous row. For example, using the values you gave: Value CumulValue CumulRounded PrevBaseline NeedĢ8.788024 100.000000 100 71 29 (100 - 71)Īt each stage, you don't round the number itself. Then use that along with the history to work out what value should be used. Probably the "best" way to do this (quoted since "best" is a subjective term) is to keep a running (non-integral) tally of where you are, and round that value. In case of a tie (3.33, 3.33, 3.33) an arbitrary decision can be made (e.g. In my mind, to remain true to the numbers, the "right" result is the one that minimizes the overall error, defined by how much error rounding would introduce relative to the actual value: value rounded error decision What's a good algorithm to represent any number of percentages as whole numbers while still maintaining a total of 100%?Įdit: After reading some of the comments and answers, there are clearly many ways to go about solving this. If I use parseInt(), I end up with a total of 97%. If I simply use Math.round(), I end up with a total of 101%. I need to represent these percentages as whole numbers. This technique is a combination of charting the right expression to support the chart’s purpose and exploiting a few chart properties to display that supportive information in a meaningful way.Consider the four percentages below, represented as float numbers: 13.626332% Another solution is to just delete the legend. If the color scheme is right, you can display the data labels in a matching color, making the relationship between the legend item and the values obvious. The legend continues to display the % Adults series, which is a bit awkward, but not a truly horrible offense. Visually (see the complete chart above) you can see that the adults make up the larger portion of chocolate lovers, but you can quickly discern that 51% of chocolate lovers are adults, 26% of strawberry lovers are adults, and 14% of vanilla lovers are adults. The addition of the % Adults value tells an important story, at just a glance. If you want, click the Font tab and reduce the size of the data label.Choose Inside Base in the Label Position section.Right-click one of the remaining data labels and choose Format Data Labels. At this point, you’re nearly done, but the remaining data labels - the % Adults percentage - probably need to be repositioned.
Right-click the legend, choose Format legend, click the Font tab, and enter 8 as the Font size.
(Depending on your settings, you might need to choose a smaller or larger font size.) Choose 8 in the Size control and click OK. Right-click any of the values on the Y axis, choose Format Axis, and click the Font tab.Right-click the X axis (the flavors), choose Format Axis from the resulting context menu, and then click the Font tab.Let’s adjust some of the formats to make the chart a bit more readable: