简体   繁体   English

javascript 转换科学计数法,如何确定 10 次方后的数字

[英]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.

相关问题 Javascript:防止 parseFloat 将大数转换为科学计数法 - Javascript: prevent parseFloat from converting large number to scientific notation 我们如何将Javascript中的科学计数法转换为数字 - How do we convert scientific notation to number in Javascript 如果不用科学记数法显示,JavaScript编号有多小? - How small can a JavaScript number be without displaying in scientific notation? 如何将包含科学记数法的字符串转换为正确的 Javascript 数字格式 - How to convert a String containing Scientific Notation to correct Javascript number format Javascript - 科学记数法受限制的最大数量是多少? - Javascript - What is the maximum number in scientific notation restricted by? 科学符号手机号码-Excel Javascript - Scientific notation mobile number - Excel Javascript 如何在javascript中将大的负科学记数字转换为十进制记号字符串? - How to convert big negative scientific notation number into decimal notation string in javascript? 如何避免 JavaScript 中大数的科学记数法? - How to avoid scientific notation for large numbers in JavaScript? JavaScript中数字的科学计数法 - Scientific notation for numbers in JavaScript 如何用科学计数法格式化数字以在Javascript中显示更少的数字? - How do I format a number in scientific notation to show less digits in Javascript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM