BigDecimal stripTrailingZeros doesn't work for zero
问题 I have met strange bug in my code. It relates with new BigDecimal("1.2300").stripTrailingZeros() returns 1.23 (correct) but new BigDecimal("0.0000").stripTrailingZeros() returns 0.0000 (strange), thus nothing happens Why? How to fix it? 回答1: Seems that it is a bug . But it is fixed in Java 8 . Direct URL for fix. There is workaround for this: BigDecimal zero = BigDecimal.ZERO; if (someBigDecimal.compareTo(zero) == 0) { someBigDecimal = zero; } else { someBigDecimal = someBigDecimal