0

I have a calculator app written in Flex/ActionScript 3 and I am struggling to understand some of parseFloat's behaviors. Any string containing a decimal value less than 0 with at least 4 places is returns as an exponent. Why does parseFloat behave this way and can I get the value as a float instead of an exponent?

parseFloat("0.004");
//returns 0.004 like I would expect

parseFloat("1.0004");
//returns 1.0004 like I would expect

parseFloat("0.0004");
//returns 4.0E-4 but I want 0.0004
Barış Uşaklı
  • 13,440
  • 7
  • 40
  • 66
  • 2
    `parseFloat("0.0004")`; traces 0.0004 for me. `var num:Number = parseFloat("0.0004"); trace(num);` Are you putting it in a string or component? Can you show more code? – Barış Uşaklı Mar 26 '13 at 20:45
  • 4.0e-4 == 0.0004, what's wrong? You need to properly format the printing of that number, that's all. – Vesper Mar 27 '13 at 03:25
  • Thanks Vesper, you're right. I just needed to switch my thinking. 4.0e-4 == 0.0004 so my focus needs to shift to the string formatting instead of the parseFloat result. – justinheuer Mar 27 '13 at 15:43

0 Answers0