import java.math.BigDecimal; import java.math.BigInteger; public class MathUtil { public static BigDecimal getBigDecimal( Object value ) { BigDecimal val = null; if( value != null ) { if( value instanceof BigDecimal ) { val = (BigDecimal) value; } else if( value instanceof String ) { val = new BigDecimal( (String) value ); } else if( value instanceof BigInteger ) { val = new BigDecimal( (BigInteger) value ); } else if( value instanceof Number ) { val = new BigDecimal( ((Number)value).doubleValue() ); } else { throw new ClassCastException("Not possible to coerce ["+value+"] from class "+value.getClass()+" into a BigDecimal."); } } return val; } }
原文地址:https://www.cnblogs.com/smdq/p/9466895.html
时间: 2024-10-11 11:49:23