javascript-number-formatter icon indicating copy to clipboard operation
javascript-number-formatter copied to clipboard

Incorrect rounding number

Open sammyhk opened this issue 6 years ago • 3 comments

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?

sammyhk avatar Jan 10 '19 04:01 sammyhk

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

rotsee avatar Jan 10 '19 08:01 rotsee

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/).

sammyhk avatar Jan 10 '19 08:01 sammyhk

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? 😸

Mottie avatar Jan 29 '19 04:01 Mottie