import java.math.BigDecimal;
import java.math.BigInteger;
/**
* Utility methods for math classes
*
* @author etirelli
*/
publicclass MathUtils {
publicstatic BigDecimal getBigDecimal( Object value ) {
BigDecimal ret = null;
if( value != null ) {
if( value instanceof BigDecimal ) {
ret = (BigDecimal) value;
} elseif( value instanceof String ) {
ret = new BigDecimal( (String) value );
} elseif( value instanceof BigInteger ) {
ret = new BigDecimal( (BigInteger) value );
} elseif( value instanceof Number ) {
ret = new BigDecimal( ((Number)value).doubleValue() );
} else {
thrownew ClassCastException("Not possible to coerce ["+value+"] from class "+value.getClass()+" into a BigDecimal.");
}
}
return ret;
}
}