Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8084113 | emb-9 | Brian Burkhalter | P4 | Resolved | Fixed | team |
FULL PRODUCT VERSION :
java version "1.8.0"
Java(TM) SE Runtime Environment (build 1.8.0-b132)
Java HotSpot(TM) 64-Bit Server VM (build 25.0-b70, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Linux tim-desktop 3.2.0-69-generic #103-Ubuntu SMP Tue Sep 2 05:02:14 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
A DESCRIPTION OF THE PROBLEM :
Printing a zero-valued BigDecimal with negative scale (e.g. 0 * 10^34) using String.format conversion 'f' prints extraneous leading zeroes, contrary to the API description.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Execute the following lines:
BigDecimal x = new BigDecimal(BigInteger.ZERO, -6);
System.out.println(String.format("%.4f", x));
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The expected output is
0.0000
ACTUAL -
The actual output is
0000000.0000
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.math.BigDecimal;
import java.math.BigInteger;
public class Temp {
public static void main(String[] args) {
BigDecimal x = new BigDecimal(BigInteger.ZERO, -6);
System.out.println(String.format("%.4f", x));
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Converting the value to a nonnegative scale works around the problem.
java version "1.8.0"
Java(TM) SE Runtime Environment (build 1.8.0-b132)
Java HotSpot(TM) 64-Bit Server VM (build 25.0-b70, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Linux tim-desktop 3.2.0-69-generic #103-Ubuntu SMP Tue Sep 2 05:02:14 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
A DESCRIPTION OF THE PROBLEM :
Printing a zero-valued BigDecimal with negative scale (e.g. 0 * 10^34) using String.format conversion 'f' prints extraneous leading zeroes, contrary to the API description.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Execute the following lines:
BigDecimal x = new BigDecimal(BigInteger.ZERO, -6);
System.out.println(String.format("%.4f", x));
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The expected output is
0.0000
ACTUAL -
The actual output is
0000000.0000
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.math.BigDecimal;
import java.math.BigInteger;
public class Temp {
public static void main(String[] args) {
BigDecimal x = new BigDecimal(BigInteger.ZERO, -6);
System.out.println(String.format("%.4f", x));
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Converting the value to a nonnegative scale works around the problem.
- backported by
-
JDK-8084113 Zero BigDecimal with negative scale prints leading zeroes in String.format
-
- Resolved
-