`desc` 需要加引号
BigDecimal progress = new BigDecimal(0.444);
progress=progress.setScale(2, BigDecimal.ROUND_HALF_UP);
或
DecimalFormat df = new DecimalFormat("###0.00");
df.setRoundingMode(RoundingMode.HALF_UP);
df.format(new BigDecimal(amount));
自动去多余的0
public static String getTrimAmount(String amount){
NumberFormat nf = NumberFormat.getInstance();
nf.setGroupingUsed(false); //不显示千位逗号
return nf.format(new BigDecimal(amount));
}
//格式化
DecimalFormat df=new DecimalFormat("0.00");
double profitrate = 0.42;
System.err.println(new Double(df.format(profitrate/100*10000/365).toString()));
//百分比
NumberFormat num = NumberFormat.getPercentInstance();
num.setMaximumIntegerDigits(3);
num.setMaximumFractionDigits(2);
double csdn = 0.02086548;
System.out.println(num.format(csdn));