【问题标题】:Getting the power of exponent获得指数的力量
【发布时间】:2019-08-22 21:03:09
【问题描述】:

假设我有一个号码:1.25e-30

我想得到这个号码的-30 部分。

我怎样才能得到它?

【问题讨论】:

  • Math.floor( Math.log10(1.25e-30))

标签: javascript numbers exponent


【解决方案1】:

使用slicelastIndexOf - 因为如果基数 (1.25) 是负数,只需使用 indexOf 即可。

const num = 1.25e-30;
const str = num.toString();

const res = str.slice(str.lastIndexOf("-"));

console.log(res);

【讨论】:

    【解决方案2】:

    试试

    (''+num.toExponential()).split('e')[1]
    

    exp = num => (''+num.toExponential()).split('e')[1]; 
    
    console.log( exp(1.25e-30) );
    console.log( exp(0.001) );
    console.log( exp(1001) );

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-08-03
      • 2021-12-19
      • 2013-05-05
      • 1970-01-01
      • 1970-01-01
      • 2021-12-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多