-
Type:
Bug
-
Resolution: Fixed
-
Priority:
P3
-
Affects Version/s: 25
-
Component/s: core-libs
-
b20
-
generic
-
generic
| Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
|---|---|---|---|---|---|---|
| JDK-8372838 | 25.0.3 | Volker Simonis | P3 | Resolved | Fixed | master |
java.text.DecimalFormat::setRoundingMode does not round input as specified by the rounding mode.
Regression: Last worked in version 21.0.8.
Sample :
import java.math.RoundingMode;
import java.text.DecimalFormat;
public class DecimalFormatExample {
public static void main(String[] args) {
DecimalFormat format = (DecimalFormat) DecimalFormat.getInstance();
format.setMaximumFractionDigits(10);
format.setRoundingMode(RoundingMode.HALF_UP);
var expected = "0.0000000001";
var actual = format.format(Double.parseDouble("0.00000000005"));
if (!expected.equals(actual)) {
throw new AssertionError("Expected: " + expected + ", Actual: " + actual);
}
}
}
This bug happens on tie cases when DecimalFormat rounds a fractional double whose least significant digit is one index past the maximum fraction digits allowed by the format.
Regression: Last worked in version 21.0.8.
Sample :
import java.math.RoundingMode;
import java.text.DecimalFormat;
public class DecimalFormatExample {
public static void main(String[] args) {
DecimalFormat format = (DecimalFormat) DecimalFormat.getInstance();
format.setMaximumFractionDigits(10);
format.setRoundingMode(RoundingMode.HALF_UP);
var expected = "0.0000000001";
var actual = format.format(Double.parseDouble("0.00000000005"));
if (!expected.equals(actual)) {
throw new AssertionError("Expected: " + expected + ", Actual: " + actual);
}
}
}
This bug happens on tie cases when DecimalFormat rounds a fractional double whose least significant digit is one index past the maximum fraction digits allowed by the format.
- backported by
-
JDK-8372838 DecimalFormat Rounding Errors for Fractional Ties Near Zero
-
- Resolved
-
- relates to
-
JDK-8314169 Combine related RoundingMode logic in j.text.DigitList
-
- Resolved
-
- links to
-
Commit(master)
openjdk/jdk25u-dev/c0391481
-
Commit(master)
openjdk/jdk/376d77e8
-
Review(master)
openjdk/jdk25u-dev/4
-
Review(master)
openjdk/jdk25u/371
-
Review(master)
openjdk/jdk/27681
(2 links to)