Why the following code prints 0.00
and not 0
?
BigDecimal big = new BigDecimal("0.00");
big = big.stripTrailingZeros();
System.out.println(big.toPlainString());
The following is the documentation for stripTrailingZeroes:
Returns BigDecimal which is numerically equal to this one but with any trailing zeros removed from the representation. For example, stripping the trailing zeros from the BigDecimal value 600.0, which has [BigInteger, scale] components equals to [6000, 1], yields 6E2 with [BigInteger, scale] components equals to [6, -2]
Returns:
a numerically equal BigDecimal with any trailing zeros removed.
I think it's a bug: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6480539
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With