limit the exponential notation decimal place to 4 in javascript

philip picture philip · Sep 1, 2011 · Viewed 8.7k times · Source

How to limit the decimal place to 4 in javascript with this type of values? the e is the exponent since I am using power of ten values. toFixed() doesn't seem to work.

1.0531436913408342e-7
-5.265718456704172e-7
8.425149530726674e7

Answer

Mikko Ohtamaa picture Mikko Ohtamaa · Sep 1, 2011

Try:

   Math.round(val*10000)/10000