简体   繁体   English

Javascript:在显示较大的unumber时如何避免科学计数法

[英]Javascript: how to avoid scientific notation when displaying large unumber

Based on http://users.dickinson.edu/~braught/courses/cs131s99/Lessons/03-Out&Data.html , for readability, JavaScript uses scientific notation to display very large numbers (absolute value greater than or equal to 1021). 为了提高可读性,JavaScript基于http://users.dickinson.edu/~braught/courses/cs131s99/Lessons/03-Out&Data.html ,使用科学计数法来显示非常大的数字(绝对值大于或等于1021)。 For example, the write statement 例如,write语句

document.write(1000000000000000000000000);

would produce the output 1e24 将产生输出1e24

Can I avoid scientific notation display? 我可以避免科学计数法显示吗?

Thanks 谢谢

It's not for readability. 不是为了提高可读性。 If an integer is larger than 2 53 (9007199254740992), then JavaScript cannot guarantee its exact storage. 如果整数大于2 53 (9007199254740992),则JavaScript无法保证其精确存储。 In your case the number is actually 999999999999999983222784. 在您的情况下,该数字实际上是999999999999999983222784。

You can use something like YourJS.fullNumber() . 您可以使用类似YourJS.fullNumber() For instance you could try something like YourJS.fullNumber(1e20) to produce 100000000000000000000 . 例如,您可以尝试使用类似YourJS.fullNumber(1e20)来产生100000000000000000000 Try out your own code here: 在这里尝试自己的代码:

https://www.yourjs.com/console/?gist=9dce161c033e7391b2f871a19006a653&file=Example+of+YourJS.fullNumber.js https://www.yourjs.com/console/?gist=9dce161c033e7391b2f871a19006a653&file=Example+of+YourJS.fullNumber.js

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

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