Balraj McCoy Balraj McCoy - 1 year ago 74
Javascript Question

How do I format a number in scientific notation to show less digits in Javascript?

For example, I have a number which is 1.3685999999999998e+35 but I just want to display 1.368e+35. I tried toFixed and toPrecision but nothing works.

Answer Source

You need to use Number.prototype.toExponential:

var x = 11827361827361872361263812631827361823618723;

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download