<i18n dev> RFR: 8262744: Formatter '%g' conversion uses wrong format for BigDecimal rounding up to limits
Joe Darcy
darcy at openjdk.java.net
Tue Apr 6 22:59:31 UTC 2021
On Tue, 6 Apr 2021 20:34:52 GMT, Ian Graves <igraves at openjdk.org> wrote:
> This fixes a bug where the formatting code for `%g` flags incorrectly tries to round `BigDecimal` after determining whether it should be a decimal numeric format or a scientific numeric format. The solution rounds before determining the correct format.
test/jdk/java/util/Formatter/BigDecimalRounding.java line 44:
> 42: public static void testBigDecimalRounding() {
> 43: var res1 = String.format("%g", 0.00009999999999999995);
> 44: var res2 = String.format("%g", 0.00009999999f);
To avoid possible vagaries in decimal -> binary conversion of double values, I suggest also testing against a BigDecimal directly rounded to the precision in question.
-------------
PR: https://git.openjdk.java.net/jdk/pull/3363
More information about the i18n-dev
mailing list