parent
bfddcfd8c1
commit
0bff634f0b
@ -0,0 +1,36 @@
|
||||
package jnpf.mobilePort.utils;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
|
||||
/**
|
||||
* @Author: WangChuang
|
||||
* @Date: 23/3/2023 上午11:30
|
||||
* @Description //注释:
|
||||
* @Version 1.0
|
||||
*/
|
||||
public class BigDecimalUtil {
|
||||
/**
|
||||
* Object转BigDecimal类型
|
||||
*
|
||||
* @param value 要转的object类型
|
||||
* @return 转成的BigDecimal类型数据
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
Loading…
Reference in new issue