I have an amount $9558.99, which I need to split between 4 people: 40%, 40%, 10%, 10% . (This is just an example where the problem surfaces)
When I calculate the fraction I get the following results, which all contain fractions of a penny, which is no good, because obviously I can’t give a person half a penny.
40% $3823.5960
40% $3823.5960
10% $955.8990
10% $955.8990
SUM $9558.99
If I round up I get a penny over:
40% $3823.60
40% $3823.60
10% $955.90
10% $955.90
SUM $9559.00 <-- 1 penny over
If I round down I get 3 penny less (again no suprise):
40% $3823.59
40% $3823.59
10% $955.89
10% $955.89
SUM $9558.96 <-- 3 pennies under
So my question is what would be the correct approach to fairly divide the amount based on the percentages?
EDIT: This might not be a programming question per-se but I think it’s related to a programmer anyway.
Round up, and subtract the excessive penny(s) randomly.
To subtract randomly, pick
nrandom people wheren= number of leftover penny(s).Intuitively speaking I believe that n will not be greater than 3 in this scenario.
(Alternatively, round down and spread remaining pennies randomly).