[英]javascript converting scientific notation, how to determine the number after power of 10
If I type a number in the browser console the result is:如果我在浏览器控制台中输入一个数字,结果是:
1000000000000000000000 --> 1e+21
0.00000000003453 --> 3.453e-11
I want to determine the number after e
.我想确定
e
之后的数字。 In this example, the number is 21
or -11
在此示例中,数字为
21
或-11
Thanks!谢谢!
You can convert the number to a string using .toExponential()
and then split based on e
and get the last element (which would be your number) like so:您可以使用
.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.