double类型后补0
private String roundByScale(double v, int scale) {
if (scale < 0) {
throw new IllegalArgumentException(
"The scale must be a positive integer or zero");
}
if(scale == 0){
return new DecimalFormat("0").format(v);
}
String formatStr = "0.";
for(int i = 0; i < scale; i++){
formatStr = formatStr + "0";
}
return new DecimalFormat(formatStr).format(v);
}
标签:scale,java,int,方法,formatStr,new,常用工具
From: https://www.cnblogs.com/xiaojianwen/p/16894732.html