Code example for BigDecimal

Methods: compareTo

0
        if( type1 != type2 ) {
            if( type1 > DECIMAL || type2 > DECIMAL )
                throw new IllegalArgumentException( "Trying to compare incompatible values " + n1 + " " + n2 );
             
            if( type1 == DECIMAL || type2 == DECIMAL ) 
                return convertToDecimal( n1 ).compareTo( convertToDecimal( n2 ) );
 
            if( type1 < type2 )
                return -sign( n2 );
            else 
                return sign( n1 );
        } 
 
        switch( type1 ) {
            case BYTE:
                return ((Byte) n1).compareTo( (Byte) n2 );
            case SHORT:
                return ((Short) n1).compareTo( (Short) n2 );
            case INT:
                return ((Integer) n1).compareTo( (Integer) n2 );
            case LONG:
                return ((Long) n1).compareTo( (Long) n2 );
            case INTEGER:
                return ((BigInteger) n1).compareTo( (BigInteger) n2 );
            case DECIMAL:
                return ((BigDecimal) n1).compareTo( (BigDecimal) n2 );
            case FLOAT:
                return ((Float) n1).compareTo( (Float) n2 );
            case DOUBLE:
                return ((Double) n1).compareTo( (Double) n2 );
            default: