小数点后补零"/>
java 小数点后补零
java保留小数点后几位,不足的补0public class Test {
public static void main(String[] args) {
String result = Test.roundByScale(2.00, 2);
System.out.println(result);
}
public static String roundByScale(double v, int scale) {
if (scale
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
formatStr = formatStr + "0";
}
return new DecimalFormat(formatStr).format(v);
}
}
本文为胖虎原创文章,转载无需和我联系,但请注明来自胖虎博客panghucat
更多推荐
java 小数点后补零
发布评论