Skip to content

sum-safe rounding for number arrays

License

Notifications You must be signed in to change notification settings

boredland/saferound

Repository files navigation

saferound

npm npm bundle size (version) npm GitHub test Coverage Status

About

saferound is a simplified typescript adaption of the python library Iteround, a sum-safe rounding library.

The library solves the problem of rounding a list of numbers whilst preserving the sum.

Usage

import saferound from 'saferound';

const result = safeRound([4.0001, 3.2345, 3.2321, 6.4523, 5.3453, 7.3422], 0); // sum = 30
expect(result).toEqual([5, 3, 4, 6, 5, 7]); // sum = 30

License

Distributed under the MIT License. See LICENSE for more information.