JAVA除法保留小数点后两位的方法

JAVA除法保留小数点后两位的方法
原创空间, 文章收藏, 网上资源

邢红瑞 发表于 2008-10-14 19:19:45 

1.(double) (Math.round(sd3*10000)/10000.0); 

这样为保持4位

(double) (Math.round(sd3*100)/100.0);

这样为保持2位.



2.另一种办法
import java.text.DecimalFormat; 

DecimalFormat df2 = new DecimalFormat("###.00");

DecimalFormat df2 = new DecimalFormat("###.000");

System.out.println(df2.format(doube_var));

第一个为2位,第二个为3位.

3 新的jdk
String.format("%10.2f%%", doube_var);