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));
第一個(gè)為2位,第二個(gè)為3位.