fredley
fredley

Reputation: 33901

Format a number with an exponent in 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?

Upvotes: 3

Views: 96

Answers (1)

epascarello
epascarello

Reputation: 207501

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.

Upvotes: 7

Related Questions