From ffc0e38d4900abc9855f196f6cbd0d5f8de8fb7e Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Thu, 26 Jan 2006 13:43:41 +0000 Subject: Fixes bug #25970 reported by Michael Kay * java/math/BigDecimal.java (compareTo): Don't strip trailing zeros. Add trailing zeros to the fraction of the decimal with the smallest scale. --- java/math/BigDecimal.java | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'java/math/BigDecimal.java') diff --git a/java/math/BigDecimal.java b/java/math/BigDecimal.java index 693c39987..94b373b04 100644 --- a/java/math/BigDecimal.java +++ b/java/math/BigDecimal.java @@ -365,16 +365,13 @@ public class BigDecimal extends Number implements Comparable // quotients are the same, so compare remainders - // remove trailing zeros - if (thisParts[1].equals (BigInteger.valueOf (0)) == false) - while (thisParts[1].mod (BigInteger.valueOf (10)).equals - (BigInteger.valueOf (0))) - thisParts[1] = thisParts[1].divide (BigInteger.valueOf (10)); - // again... - if (valParts[1].equals(BigInteger.valueOf (0)) == false) - while (valParts[1].mod (BigInteger.valueOf (10)).equals - (BigInteger.valueOf (0))) - valParts[1] = valParts[1].divide (BigInteger.valueOf (10)); + // Add some trailing zeros to the remainder with the smallest scale + if (scale < val.scale) + thisParts[1] = thisParts[1].multiply + (BigInteger.valueOf (10).pow (val.scale - scale)); + else if (scale > val.scale) + valParts[1] = valParts[1].multiply + (BigInteger.valueOf (10).pow (scale - val.scale)); // and compare them return thisParts[1].compareTo (valParts[1]); -- cgit v1.2.1