-
Bug
-
Resolution: Fixed
-
P3
-
25
-
b20
-
generic
-
generic
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.
- relates to
-
JDK-8314169 Combine related RoundingMode logic in j.text.DigitList
-
- Resolved
-
- links to
-
Commit(master)
openjdk/jdk/376d77e8
-
Review(master)
openjdk/jdk/27681