问题
I have a problem with javascript number. My problem is that I have a currency field in HTML and when I use javascript to calculate with another field; then if this input field has the number of digits > 15 then this is auto rounded. You can try this in firebug. E.g:
(9999999999999999);
10000000000000000
How do I fix this?
回答1:
the following link may help you
Large numbers erroneously rounded in Javascript
Also, this library will help to find a workaround http://www.leemon.com/crypto/BigInt.html
Regards, Cyril
回答2:
You have a currency field that you care is rounding past 9999999999999999??
I'm impressed right there :P
It's a limitation of having large floating point numbers. There's no easy way to fix it short of getting a bigint javascript library, I'm sure there's a few out there. But honestly, why do you care?
回答3:
Chk this link for an explanation of WHY
http://www.exploringbinary.com/print-precision-of-floating-point-integers-varies-too/
来源:https://stackoverflow.com/questions/5590937/why-is-a-number-having-greater-than-15-digits-auto-rounded-in-javascript