-
Bug
-
Resolution: Unresolved
-
P4
-
8, 9
-
Cause Known
-
generic
-
generic
PrintStream.printf (i.e. java.util.Formater printf) is suffering the same kind of rounding problems
that was found in java.text.DecimalFormat/DigitList : erroneous double rounding
The following code:
double d = 12.225d;
System.out.println("BigDecimal output for " + d + " -> " + new BigDecimal(d).toString());
System.out.printf("test %1$.2f \n", 12.225d);
shows that printf will wrongly round up, following half-up rounding rule specified by
Format string syntax in Formatter.
Result from the above is the following output :
> BigDecimal output for 12.225 -> 12.2249999999999996447286321199499070644378662109375
> test 12.23
the printf call shoud provide "test 12.22" since the double d is below the tie.
that was found in java.text.DecimalFormat/DigitList : erroneous double rounding
The following code:
double d = 12.225d;
System.out.println("BigDecimal output for " + d + " -> " + new BigDecimal(d).toString());
System.out.printf("test %1$.2f \n", 12.225d);
shows that printf will wrongly round up, following half-up rounding rule specified by
Format string syntax in Formatter.
Result from the above is the following output :
> BigDecimal output for 12.225 -> 12.2249999999999996447286321199499070644378662109375
> test 12.23
the printf call shoud provide "test 12.22" since the double d is below the tie.
- relates to
-
JDK-8087313 Rounding HALF_DOWN issue
- Closed
-
JDK-7131459 [Fmt-De] DecimalFormat produces wrong format() results when close to a tie
- Closed