Opposite of Number.toExponential in JS

前端 未结 5 640
感情败类
感情败类 2020-12-10 16:36

I need to get the value of an extremely large number in JavaScript in non-exponential form. Number.toFixed simply returns it in exponential form as a string, wh

5条回答
  •  难免孤独
    2020-12-10 16:46

    The answer is there's no such built-in function. I've searched high and low. Here's the RegExp I use to split the number into sign, coefficient (digits before decimal point), fractional part (digits after decimal point) and exponent:

    /^([+-])?(\d+)\.?(\d*)[eE]([+-]?\d+)$/
    

    "Roll your own" is the answer, which you already did.

提交回复
热议问题