mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-07 22:44:49 +00:00
ICU-20000 Workaround for BigDecimal.stripTrailingZeros() differences. (#57)
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.
This commit is contained in:
parent
01ca8fb555
commit
da7bd533ab
1 changed files with 5 additions and 1 deletions
|
@ -40,7 +40,11 @@ public class Scale {
|
|||
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();
|
||||
|
|
Loading…
Add table
Reference in a new issue