Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6664028

Float.toString(float) returns too many digits

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 6
    • core-libs

      FULL PRODUCT VERSION :
      java version "1.6.0_02"
      Java(TM) SE Runtime Environment (build 1.6.0_02-b05)
      Java HotSpot(TM) 64-Bit Server VM (build 1.6.0_02-b05, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Linux tidore 2.6.20-gentoo-r8 #3 SMP Tue Aug 21 11:38:15 CEST 2007 x86_64 AMD Athlon(tm) 64 X2 Dual Core Processor 3800+ AuthenticAMD GNU/Linux


      A DESCRIPTION OF THE PROBLEM :
      According to the javadoc, Float.toString(float) should return a representation of its argument with as few digits as possible (but at least one). For several values, such as 1.0E17, it returns many more digits.

      Both "1.0E17" and "9.9999998E16" are representations of the float value passed as an argument in the test case. Because the former has the fewest digits, it is the required result.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile and run source included below.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      1.0E17
      ACTUAL -
      9.9999998E16

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public class FloatToStringBug {
        public static void main(String[] args) {
          System.err.println(Float.toString(1.0E17f));
        }
      }

      ---------- END SOURCE ----------

            rgiulietti Raffaello Giulietti
            ryeung Roger Yeung (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: