Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Format a number with an exponent in javascript?

Tags:

javascript

I have a number which is displaying as follows:

1.0333333333333335e-9

I'd like to limit the number of digits that's shown, so it looks more like:

1.03e-9

How do I do this?

like image 933
fredley Avatar asked Nov 26 '25 02:11

fredley


1 Answers

numObj.toExponential(fractionDigits) has it built in

fractionDigits

An integer specifying the number of digits after the decimal point. Defaults to as many digits as necessary to specify the number.

like image 124
epascarello Avatar answered Nov 28 '25 15:11

epascarello



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!