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位.

相关文章:

  • 2021-05-15
  • 2022-12-23
  • 2021-12-29
  • 2021-12-18
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-18
  • 2022-12-23
  • 2021-06-23
相关资源
相似解决方案