1 Reply Latest reply on Jul 26, 2006 1:18 PM by peterent

    Subtraction Issue

    DamionA
      I am working on a project in Flex 2 using the Eclipse plugin. I have ran into an issue with a simple subtract statment that I can not figure out why it is doing this.

      Alert.show(String(10000.30-2000.00));

      After running this code as a test, it is returning 8000.29999999999 and not the proper 8000.30. Has anyone had, seen, or know why the application would act in this fasion?

      Damion
        • 1. Re: Subtraction Issue
          peterent Level 2
          It is a number representation problem. It happens in many languages and has been a problem since floating point values were introduced to computers.

          If you intend on showing a number it is best to format it:

          <mx:NumberFormatter id="nfmt" precision="2" />

          Alert.show( nfmt.format(10000.30-2000.00) );