static Object convert ( Object object , Class < ? > otherType ) { if ( otherType == BigDecimal . class ) { if ( object instanceof BigInteger ) { return new BigDecimal ( ( BigInteger ) object ) ; } else if ( object instanceof Number ) { return BigDecimal . valueOf ( ( ( Number ) object ) . doubleValue ( ) ) ; } } else if ( otherType == BigInteger . class ) { if ( ! ( object instanceof BigDecimal ) && ( object instanceof Number ) ) { return BigInteger . valueOf ( ( ( Number ) object ) . longValue ( ) ) ; } } return object ; }
This method converts the given value to a more common type .