How can I convert numbers into scientific notation?

Samar picture Samar · Jun 20, 2012 · Viewed 19k times · Source

I want to make a function that takes an entered value and converts it to scientific notation (N x 10^a)

I've tried many different things, but I can't seem to get it right.

Example:

I enter 200. The converter converts it to 2 x 10^2

Answer

Hunter McMillen picture Hunter McMillen · Jun 20, 2012

You can do something like this:

a = 200
a.toExponential(); //output 2e+2

fiddle: http://jsfiddle.net/Q8avJ/9/