Why is a number having greater than 15 digits auto rounded in javascript? [duplicate]

冷暖自知 提交于 2019-12-08 07:35:48

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!