5 Replies Latest reply on Jul 22, 2008 10:34 AM by Some1Won

    parseFloat() oddity


      This is one of the most bizarre things I’ve seen in actionscript: comparing 2 numbers and it comes out wrong.

      In the code below, for some odd reason “312346.46”, parsed to a float, then multiplied by 100, and compared to 31234646 is wrong. Seems any kind of comparison is wrong. Yet values like: “390000.16” compared to 39000016, gone though the same thing is correct.

      However, I’m not sure if this is really a ‘fix’ as I don’t even know what’s wrong, if I wrap Math.round() around everything, it seems to be okay. (Though, this could cause problems in the future...)

      var balance:Number = parseFloat(inputString) * 100;

      var balance:Number = Math.round(parseFloat(inputString) * 100);

      Any ideas?