Extracting the exponent and mantissa of a Javascript Number

后端 未结 8 656
执笔经年
执笔经年 2020-12-03 03:03

Is there a reasonably fast way to extract the exponent and mantissa from a Number in Javascript?

AFAIK there\'s no way to get at the bits behind a Number in Javascri

8条回答
  •  臣服心动
    2020-12-03 04:09

    What about following to get the exponent?:

    let exp = String(number.toExponential());
    exp = Number(exp.substr(exp.lastIndexOf('e')+1));
    

    1000 will result in exp = 3

提交回复
热议问题