javascript-number-formatter
javascript-number-formatter copied to clipboard
Incorrect rounding number
We got issue on the rounding, example:
format("0.00", "7.165") got "7.17"
but
format("0.00", "8.165") got "8.16"
May I ask if any option can make them rounding consistent or this is a bug?
This issue lies with Javascript (or floating point operations in general), rather than with this library, I think. You can try for yourself:
Math.round(7.165*100)/100
7.17
Math.round(8.165*100)/100
8.16
Thank you for quick response. Yes, from the source code, it is using .toFixed(...) to do the rounding which have the same issue about the floating point precision in Javascript.
As a library, can you provide an option or extension point for developer to plug in some high precision math library (e.g. http://mathjs.org/).
Hi @sammyhk!
Thanks for report!... I've been super busy and forgot to include an enhancement in the release I just published. I'll try to get to it soon-ish. Unless you're up for submitting a PR? 😸