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 ----------
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 ----------
- duplicates
-
JDK-4511638 Double.toString(double) sometimes produces incorrect results
-
- Resolved
-
- relates to
-
JDK-4511638 Double.toString(double) sometimes produces incorrect results
-
- Resolved
-
-
JDK-4191279 Float.toString() produces incorrect results
-
- Closed
-