Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clarification on behavior of BigDecimal.stripTrailingZeroes()

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.
like image 797
Leonid Avatar asked Mar 08 '11 22:03

Leonid


1 Answers

I think it's a bug: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6480539

like image 85
Neil Avatar answered Nov 07 '22 07:11

Neil