![](/img/trans.png)
[英]Javascript: prevent parseFloat from converting large number to scientific notation
[英]javascript converting scientific notation, how to determine the number after power of 10
如果我在浏览器控制台中输入一个数字,结果是:
1000000000000000000000 --> 1e+21
0.00000000003453 --> 3.453e-11
我想确定e
之后的数字。 在此示例中,数字为21
或-11
谢谢!
您可以使用.toExponential()
将数字转换为字符串,然后基于e
拆分并获取最后一个元素(这将是您的数字),如下所示:
const getExp = n => +(n.toExponential().split('e').pop()) console.log(getExp(1000000000000000000000)) // 21 console.log(getExp(0.00000000003453)); // -11 console.log(getExp(0.000324)); // -4
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.