简体   繁体   English

JavaScript错误的整数除法结果

[英]JavaScript wrong integer division result

I can't figure out the reason 100000000000000030/10 = 10000000000000004 in JavaScript, I haven't seen this problem in other questions. 我无法弄清楚原因100000000000000030/10 = 10000000000000004在JavaScript中,我还没有在其他问题中看到过这个问题。

  <script> alert(100000000000000030/10); </script> 

Before doing this calculation you may want to know that whether this number is a safe javascript number or not. 在进行此计算之前,您可能想知道此数字是否是安全的javascript编号。 you can use - Number.isSafeInteger(100000000000000030), to know that. 你可以使用 - Number.isSafeInteger(100000000000000030)来了解这一点。

"The MAX_SAFE_INTEGER constant has a value of 9007199254740991 (9,007,199,254,740,991 or ~9 quadrillion). The reasoning behind that number is that JavaScript uses double-precision floating-point format numbers as specified in IEEE 754 and can only safely represent numbers between -(253 - 1) and 253 - 1." “MAX_SAFE_INTEGER常量的值为9007199254740991(9,007,199,254,740,991或~9千万亿)。这个数字背后的原因是JavaScript使用IEEE 754中规定的双精度浮点格式数字,并且只能安全地表示 - (253 - 1)和253 - 1.“

You may also want to read more here - Division and remainder of large numbers in JavaScript 您可能还想在此处阅读更多内容 - JavaScript中的大数字的除法和余数

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM