![](/img/trans.png)
[英]How to prevent very small numbers from being converted to scientific notation?
[英]scientific notation with small numbers
我需要处理以科学记数法书写的数字。 我知道目前 JS 仅对大小数字使用科学记数法。
例子:
1000000000000000000000 === 1e+21
0.0000001 === 1e-7
我希望每个数字都使用相同的符号。
例子:
10
应该是1e+1
我已经尝试使用.toExponential
方法,但数字被转换为string
。
我需要保留number
类型。
有什么建议吗?
您可以使用Number
将科学记数法字符串转换回数字。 .toExponential
将在规范中返回一个字符串,所以这就是你得到的。
console.log( Number('1e+4') ); console.log( Number('1e-4') ); console.log( typeof Number('1e-4') );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.