1.0.0 • Published 4 years ago

stable-sum-round v1.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

StableSumRound Build Status

The stable sum rounder is a function that takes in a set of values to be rounded, and rounds them in a way to ensure the sum of the rounded numbers is stable after they have been individually rounded. A common use case is when rounding percentages, you can ensure that the total remains stable at 100% (see the example below).

Standard RoundingStableSum
33.33%33.34%
33.33%33.33%
33.33%33.33%
Total99.99%100%
stableSumRound(2, [33.3333, 33.3333, 33.3333]);
//returns [33.34, 33.33, 33.33]
stableSumRound(0, [1.5, 1.5, 1.5, 1.5]);
//returns [1, 2, 1, 2]