2 Replies Latest reply on May 29, 2007 3:59 PM by 807606

    ++ increment of float inacurate with no compiles warnings???


      I have a simple class that uses the ++ opperator to increment a floting point variable. However the result is not correct and there are no compiler warnings about loss of precision. The class is....
      class Test
          public static void main(String[] args)
              float x = 1.123f;
      However the result of X is 2.1230001. X will now fail any if statements such as
      if (x = 2.123)
              // Do Something
      So my question is
      1) Why does this happen
      2) Is it possible to use the ++ operator on a floating point variable with accuracy?

      I'm studying for the SCJP and attention to details like this is everything!!
      Alan K.