mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +02:00
8262744: Formatter '%g' conversion uses wrong format for BigDecimal rounding up to limits
Reviewed-by: rriggs, bpb
This commit is contained in:
parent
4413dbfbdb
commit
0bdc3e7a41
2 changed files with 65 additions and 4 deletions
|
@ -3821,11 +3821,10 @@ public final class Formatter implements Closeable, Flushable {
|
|||
else if (precision == 0)
|
||||
prec = 1;
|
||||
|
||||
BigDecimal tenToTheNegFour = BigDecimal.valueOf(1, 4);
|
||||
BigDecimal tenToThePrec = BigDecimal.valueOf(1, -prec);
|
||||
value = value.round(new MathContext(prec));
|
||||
if ((value.equals(BigDecimal.ZERO))
|
||||
|| ((value.compareTo(tenToTheNegFour) != -1)
|
||||
&& (value.compareTo(tenToThePrec) == -1))) {
|
||||
|| ((value.compareTo(BigDecimal.valueOf(1, 4)) != -1)
|
||||
&& (value.compareTo(BigDecimal.valueOf(1, -prec)) == -1))) {
|
||||
|
||||
int e = - value.scale()
|
||||
+ (value.unscaledValue().toString().length() - 1);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue