昨天一个项目里面要用到向上舍入并保留两位小数,在网上找了很多都是四舍五入的,所以在这里记录下来
public static String priceFormat(double price) {
price = Math.ceil(price * 100) / 100;
String str = "0";
double anotherNan = Double.NaN;
if (Double.compare(price, anotherNan) != 0) {
DecimalFormat df1 = new DecimalFormat("###,##0.00");
BigDecimal b = new BigDecimal(price);
str = df1.format(b);
}
return str;
}