import java.text.DecimalFormat;
    import java.util.Locale;
    public class DecimalFormat2 {
        public static void main(String args[]) {
            // 得到本地的缺省格式
            DecimalFormat df = new DecimalFormat("#####.000");
            System.out.println(df.format(122.5612));
            System.out.println(df.format(122.5678));
            
        }
    }

解决方案 »

  1.   

    private static String formatNumber(double number){
    String strNum = Double.toString(number);
    if (strNum.indexOf(".") != -1){
    String dotLen = strNum.substring(strNum.indexOf(".")+1);
    if (dotLen.length()>3){
    double iValue = Double.parseDouble(dotLen.substring(3,4));
    if (iValue > 5){
    String temp = Double.toString(number + 0.001);
    strNum = temp.substring(0,temp.indexOf(".")+4);
    }
    }else{
    if (dotLen.length() == 2){
    strNum = strNum+ "0";
    }else{
    strNum = strNum+"00";
    }
    }
    }
    return strNum;
    }
    自己写的方法,还是cozmic(蓝色的猪) 用的好。学习!
      

  2.   

    自己也搞定了,感谢蓝色的猪、newsea008(J-LOVE)