警报结果不同的代码。

时间:2021-01-12 21:22:27

if use big number in "alert" or "console.log" return bad result. Example:

如果在“alert”或“console.log”中使用大数字返回错误结果。例:

alert(999999999999999999);

Result:

结果:

1000000000000000000

But we dont have any problem on alert(999999999999999); or alert(99999999999999999999999999999);

但我们在警报时没有任何问题(999999999999999);或警报(99999999999999999999999999999);

1 个解决方案

#1


4  

As the maximum integer in js is 253 or 9007199254740992 (see the link Jonathan Lonowski mentioned: What is JavaScript's Max Int? ) every number that exceeds this limit is not an integer anymore but a float.

由于js中的最大整数是253或9007199254740992(参见Jonathan Lonowski提到的链接:什么是JavaScript的Max Int?),超过此限制的每个数字不再是整数,而是浮点数。

As you can only represent certain numbers using floats. The result of an input value that is larger then an integer would - most of the time - be an aproximated one. That's why you get those results when you alert or console.log.

因为你只能用浮点数表示某些数字。输入值大于整数的结果 - 大部分时间 - 是一个近似的结果。这就是您在发出警报或console.log时获得这些结果的原因。

#1


4  

As the maximum integer in js is 253 or 9007199254740992 (see the link Jonathan Lonowski mentioned: What is JavaScript's Max Int? ) every number that exceeds this limit is not an integer anymore but a float.

由于js中的最大整数是253或9007199254740992(参见Jonathan Lonowski提到的链接:什么是JavaScript的Max Int?),超过此限制的每个数字不再是整数,而是浮点数。

As you can only represent certain numbers using floats. The result of an input value that is larger then an integer would - most of the time - be an aproximated one. That's why you get those results when you alert or console.log.

因为你只能用浮点数表示某些数字。输入值大于整数的结果 - 大部分时间 - 是一个近似的结果。这就是您在发出警报或console.log时获得这些结果的原因。