JDK-6575880 : Float.toString(float) adds trailing zeros
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 6
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux
  • CPU: x86
  • Submitted: 2007-06-30
  • Updated: 2010-04-04
  • Resolved: 2009-12-02
Related Reports
Duplicate :  
Description
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 ----------

Comments
EVALUATION Duplicate of 4428022; closing accordingly.
02-12-2009

EVALUATION Possibly duplicate of 4191279.
02-07-2007