double 直接舍去 保留两位小数

 1     public static Double twoPoint(double temp){
 2         String strNum = String.valueOf(temp);
 3         String ss= "";
 4         int a = strNum.indexOf(".");
 5         if(a>0){
 6             //获取小数点后面的数字
 7             String dianAfter = strNum.substring(a+1);
 8             if(dianAfter.length()>=2){
 9                 ss=strNum.substring(0,a+3);
10             }else {
11                 ss = strNum+"0";
12             }
13         }else{
14             ss=strNum+".00";
15         }
16         return Double.parseDouble(ss);
17     }
原文地址:https://www.cnblogs.com/difme/p/7069159.html