1

I have to convert the float to exponential..

0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000021

Using

parseFloat(result)

Gives 2.1e-87

But

10000000

Gives 10000000 (same) but I like to get 100.0e+3 etc..So I used parseFloat(result).toExponential(3); But the problem here is it is truncating everything ev even if it has more values for example 111222333 it makes it as 111.22+3 so while I reconverting as integer I am cannot get the original value..

Is there any javascript function to achieve this or how can I achieve this..

Thanks in advance..

Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
Dilip Rajkumar
  • 7,006
  • 6
  • 60
  • 76
  • Hi @FelixKling I searched SO for this solution several times but I could not find it.. only then I created this task.. that question does not hit my search parameter itself.. – Dilip Rajkumar Jun 18 '13 at 12:00

1 Answers1

4

If you use toExponential() with out the parameter, it will not drop the fractions:

console.log( (111222333).toExponential() ); // "1.11222333e+8"

The parameter specifies the amount of digits after the decimal point. If you drop it, it displays as many digits as needed (wrt to the double precision JavaScript uses internally).

Sirko
  • 72,589
  • 19
  • 149
  • 183