object转bigdecimal的具体步骤是什么呢、一起来看下吧:
用Map
对象转换成Bigdecimal的代码如下:
import java.math.BigDecimal;
import java.math.BigInteger;
public class MathUtils {
public static BigDecimal getBigDecimal( Object value ) {
BigDecimal ret = null;
if( value != null ) {
if( value instanceof BigDecimal ) {
ret = (BigDecimal) value;
} else if( value instanceof String ) {
ret = new BigDecimal( (String) value );
} else if( value instanceof BigInteger ) {
ret = new BigDecimal( (BigInteger) value );
} else if( value instanceof Number ) {
ret = new BigDecimal( ((Number)value).doubleValue() );
} else {
throw new ClassCastException("Not possible to coerce ["+value+"] from class "+value.getClass()+" into a BigDecimal.");
}
}
return ret;
}
}以上就是小编今天的分享,希望可以帮助到大家。