View Full Version : Exponential to Number.

12-14-2009, 05:48 AM
Hi All,

I have a problem in javascript.

When i am doing rounding of the value i am getting the o/p like 2.2e4.

I have to display this value in decimal value(2.0002) not in exponential.

Can any one please help me to resolve this issue.?


Old Pedant
12-14-2009, 06:27 AM
Um...you apparently don't understand what 2.2e4 means.

2.2e4 is the same as 22000.0

2.2e-4 would be the same as 0.00022

I'm actually surprised that you would ever get "2.2e4". Are you sure it wasn't "2.2e-4"???

Anyway, you *can* control the display using toFixed( n ) where n is the number of digits to be shown after the decimal point.


var num = 2.2e4;
alert( num.toFixed(2) ); // would show 22000.00
var num = 2.2e-4;
alert( num.toFixed(2) ); // would show 0.00 -- because the 0.00022 "rounds" to just 0.00
var num = 2.2e-4;
alert( num.toFixed(6) ); // would show 0.000220

And so on.