/**
* 四舍五入保留两位
*
* @param money
*
* @return
*/
public static String totalMoney(double money) {
java.math.BigDecimal bigDec = new java.math.BigDecimal(money);
double total = bigDec.setScale(2, java.math.BigDecimal.ROUND_HALF_UP)
.doubleValue();
DecimalFormat df = new DecimalFormat("0.00");
return df.format(total);
}
本文介绍了一种使用Java进行数值处理的方法,具体为将任意浮点数通过四舍五入的方式保留到小数点后两位,并展示了具体的实现代码。
4558





