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

Float.toString(float) adds trailing zeros

XMLWordPrintable

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

      FULL PRODUCT VERSION :


      ADDITIONAL OS VERSION INFORMATION :
      Linux 2.6.21-1.3194.fc7

      A DESCRIPTION OF THE PROBLEM :
      If this method is called with 0.001f through to 0.009f, a trailing 0 is added to
      the String returned. For example, 0.001f will be converted to "0.0010" when it
      should be converted to "0.001".


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      System.out.println(new Float("0.000f").toString());
      System.out.println(new Float("0.001f").toString());
      System.out.println(new Float("0.002f").toString());
      System.out.println(new Float("0.003f").toString());
      System.out.println(new Float("0.004f").toString());
      System.out.println(new Float("0.005f").toString());
      System.out.println(new Float("0.006f").toString());
      System.out.println(new Float("0.007f").toString());
      System.out.println(new Float("0.008f").toString());
      System.out.println(new Float("0.009f").toString());
      System.out.println(new Float("0.010f").toString());

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      0.0
      0.001
      0.002
      0.003
      0.004
      0.005
      0.006
      0.007
      0.008
      0.009
      0.01
      ACTUAL -
      0.0
      0.0010
      0.0020
      0.0030
      0.0040
      0.0050
      0.0060
      0.0070
      0.0080
      0.0090
      0.01

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      System.out.println(new Float("0.000f").toString());
      System.out.println(new Float("0.001f").toString());
      System.out.println(new Float("0.002f").toString());
      System.out.println(new Float("0.003f").toString());
      System.out.println(new Float("0.004f").toString());
      System.out.println(new Float("0.005f").toString());
      System.out.println(new Float("0.006f").toString());
      System.out.println(new Float("0.007f").toString());
      System.out.println(new Float("0.008f").toString());
      System.out.println(new Float("0.009f").toString());
      System.out.println(new Float("0.010f").toString());
      ---------- END SOURCE ----------

            darcy Joe Darcy
            ryeung Roger Yeung (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: