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

前端 未结 5 1895
青春惊慌失措
青春惊慌失措 2020-12-01 05:14

Suppose we have a list of items with an integer:

USA:       3 people
Australia: 2 people
Germany:   2 people

If we calculate the percentage

5条回答
  •  感动是毒
    2020-12-01 06:15

    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
    

提交回复
热议问题