/**
* description :double类型四舍五入
* creation date:
* param : number为保留位数
*/
public double round(Double v, int number) {
if (number < 0) {
throw new IllegalArgumentException("比例必须是正整数或零");
}
BigDecimal b = null == v ? new BigDecimal("0.0") : new BigDecimal(Double.toString(v));
BigDecimal one = new BigDecimal("1");
return b.divide(one, number, BigDecimal.ROUND_HALF_UP).doubleValue();
}
double类型四舍五入
最新推荐文章于 2021-09-23 10:40:49 发布