How to deal with the sum of rounded percentage not being 100?

Components may not sum to totals because of rounding. Standard in statistical reports.

The cheats will come back to bite you in the next table, report or appendix. You can't keep track of the changes. It only looks funny to people who don't read these kind of reports.

Oh yeah. Its not a rounding error.


You can refer to the Largest Remainder Method used in election: Wikipedia: Largest Remainder Method

In your case, you have

USA:       42.857...
Australia: 28.571...
Germany:   28.571...

If you take the integer part, you get

USA:       42
Australia: 28
Germany:   28

which adds up to 98, and you want to take two more. Now, you look at the decimal parts, which are

USA:       0.857...
Australia: 0.571...
Germany:   0.571...

and take the largest ones until the total reaches 100. If you take USA, the total becomes 99, and you want to take one more. Here the problem arises. Since you are left with a tie of 0.571... between Australia and Germany, if you take both, the total will be 101. So you have two ways to choose from:

(a) If you strongly want the total to be 100, just take Australia, and take no more:

USA:       43
Australia: 29
Germany:   28

(b) If you rather want to respect the fact that Australia and Germany are in a tie, you stop at that point:

USA:       43
Australia: 28
Germany:   28

You may "cheat" a bit by summing all the rounded results but the last and giving to the last one the value of 100 - the previous sum...

In this case, you would have :

USA = 43
Aus = 29
Ger = 28  (100 - (43 + 29))

But that's only a dirty trick... You should rather follow the more honest/accurate solution given by Matt as mine seems to indicate that Germany percentage is less than Australian one.


Option 1

If you are concerned about the results looking a bit strange to the user, I would put a footnote regarding the results mentioning that percentages have been rounded and may not total to 100%. You could programmatically display the message only when the rounding causes this behavior.

USA percentage:       43
Australia percentage: 29
Germany percentage:   29

*Percentages may not total 100 due to rounding

Option 2

Since you are using Ruby, I would suggest using rational numbers. This way you don't lose the precision when needed. Instead of the footnote, you might display the percentage with the rational numbers next to it like the following:

USA percentage:       43 (3/7)
Australia percentage: 29 (2/7)
Germany percentage:   29 (2/7)

Option 3

Include more decimal places so that the rounding error is less severe:

USA percentage:       42.9
Australia percentage: 28.6
Germany percentage:   28.6

This results in 100.1 instead of 101.

Tags:

Ruby

Rounding