JAVA 保留几位小数的问题
首先定义:
? java.text.DecimalFormat?? df=new?? java.text.DecimalFormat("#0.00");?
?
再是:
x = 83.3333333333;
df.format(x);?
?
结果: 83.33
-----------------------------------------------------------------
保留三位小数:
? double x= 0.666666;
??DecimalFormat df5 = new DecimalFormat("0.000");
??System.out.println(df5.format(x));