varunsrin / rusty_money

Money library for Rust
MIT License
85 stars 32 forks source link

`allocate()` allocate remainder incorrectly #103

Open hms5232 opened 7 months ago

hms5232 commented 7 months ago

If the total to be allocated cannot be divided fully, it will add remainder to each ratio which in order.

For example, we need to divide $613 to participants with $98, $92, $98, $123, $102, $92. It will be:

98 => 100
92 => 94
98 => 99
123 => 124
102 => 103
92 => 93

but if we change the order of ratios to $123, $102, $98, $98, $92, $92:

123 => 125
102 => 104
98 =>99
98 =>99
92 => 93
92 => 93

This behaviour is not fair. The remainder should be allocated by ratio size, not order.