JDK-6664028 : Float.toString(float) returns too many digits
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 6
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • OS: linux
  • CPU: x86
  • Submitted: 2008-02-15
  • Updated: 2019-10-02
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdUnresolved
Related Reports
Relates :  
Description
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 ----------

Comments
EVALUATION Appears to be a duplicate of 4642835.
21-02-2008