Code example for BigDecimal

Methods: compareTo

0
                    return n1.compareTo(n2);
                } 
                case BIGDECIMAL: {
                    BigDecimal n1 = toBigDecimal(first);
                    BigDecimal n2 = toBigDecimal(second);
                    return n1.compareTo(n2);
                } 
            } 
            // Make the compiler happy. getCommonClassCode() is guaranteed to  
            // return only above codes, or throw an exception. 
            throw new Error();
        } 
     
        public Number add(Number first, Number second) throws TemplateException {
            switch(getCommonClassCode(first, second)) {
                case INTEGER: {
                    int n1 = first.intValue();
                    int n2 = second.intValue();
                    int n = n1 + n2;
                    return 
                        ((n ^ n1) < 0 && (n ^ n2) < 0) // overflow check