Different implementations of BigDecimal.stripTrailingZeros(), in
different versions of the JDK (and different versions of Android), have
differences in their handling of zero. To avoid this, ICU4J can return
BigDecimal.ZERO for any value that is equal to zero, instead of calling
BigDecimal.stripTrailingZeros() in this problematic case.
private Scale(int magnitude, BigDecimal arbitrary, MathContext mc) {
if (arbitrary != null) {
// Attempt to convert the BigDecimal to a magnitude multiplier.
- arbitrary = arbitrary.stripTrailingZeros();
+ // ICU-20000: JDKs have inconsistent behavior on stripTrailingZeros() for Zero.
+ arbitrary =
+ arbitrary.compareTo(BigDecimal.ZERO) == 0
+ ? BigDecimal.ZERO
+ : arbitrary.stripTrailingZeros();
if (arbitrary.precision() == 1 && arbitrary.unscaledValue().equals(BigInteger.ONE)) {
// Success!
magnitude -= arbitrary.scale();