scurker / currency.js

A javascript library for handling currencies
https://currency.js.org
MIT License
3.15k stars 142 forks source link

rounding error #451

Closed lordofthebrain closed 1 year ago

lordofthebrain commented 1 year ago

Here some examples:

currency(1.25, { precision: 1 }); // => "1.3" correct currency(-1.25, { precision: 1 }); // => "-1.2" not correct should be "-1.3" currency(-1.251, { precision: 1 }); // => "-1.3" correct currency(-1.26, { precision: 1 }); // => "-1.3" correct

I do not know why the one case does not work. Please fix.

scurker commented 1 year ago

This is intended behavior. Currency follows a round half up methodology so half values will always round up. If you want a different formatted value, you could potentially pass in a custom format function to do so.