if (scale == val.scale) return intVal.compareTo (val.intVal);  BigInteger thisParts[] = intVal.divideAndRemainder (BigInteger.valueOf (10).pow (scale)); BigInteger valParts[] = val.intVal.divideAndRemainder (BigInteger.valueOf (10).pow (val.scale));  int compare; if ((compare = thisParts[0].compareTo (valParts[0])) != 0) return compare;     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));   return thisParts[1].compareTo (valParts[1]);
return compareTo((BigDecimal) obj);
  public int compareTo (BigDecimal val)   {    if (scale == val.scale)      return intVal.compareTo (val.intVal);    BigInteger thisParts[] =       intVal.divideAndRemainder (BigInteger.valueOf (10).pow (scale));    BigInteger valParts[] =      val.intVal.divideAndRemainder (BigInteger.valueOf (10).pow (val.scale));        int compare;    if ((compare = thisParts[0].compareTo (valParts[0])) != 0)      return compare;    // quotients are the same, so compare remainders    // 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]);  }