String.format("%.nf",d);----表示保留N位
public static void main(String[] args) {
double d = 3.1415926;
String result1 = String.format("%.2f", d);
String result = String.format("%.3f", d);
System.out.println(result1);//3.14
System.out.println(result);//3.142
}
原文地址:https://www.cnblogs.com/eternityz/p/12238749.html
时间: 2024-11-09 04:01:36