Double 四舍五入保留小数

Double  四舍五入保留小数:


package com.conserv.tsas.common.util;
import java.math.BigDecimal;
public class NumberUtils {
/**
* @example roundUpNumber(20.47, 0) = 20.5  ||  roundUpNumber(20.475, 0) = 20.48
* @description round up double number
* @param Double d
* @param Integer index
* @return
*/
public static Double roundUpNumber(Double d, Integer index) {
d = new BigDecimal(Double.toString(d)).setScale(index.intValue(), BigDecimal.ROUND_HALF_UP).doubleValue();
return d;
}

}


猜你喜欢

转载自www.cnblogs.com/mqxnongmin/p/10877174.html
今日推荐