scurker / currency.js

A javascript library for handling currencies

Home Page:https://currency.js.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

rounding error

lordofthebrain opened this issue · comments

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.

commented

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.