小数点后面保留3位

解决方案 »

  1.   

    SimpleDateFormat format=new SimpleDateFormat("#.###");
      

  2.   

    double d=Double.parseDouble("415.230150");
        java.text.DecimalFormat df=new java.text.DecimalFormat("##.000");
        System.out.println(df.format(d));
      

  3.   

    保留三位,并且对第四位四舍五入
        double d=Double.parseDouble("12340.230950");
        java.text.DecimalFormat df=new java.text.DecimalFormat("0.000");
        System.out.println(df.format(d));
      

  4.   

    哈哈,刚想起来
    我怎么会写上SimpleDateFormat呢?可能这两天搞日期输出太多了,傻掉了用DecimalFormat sorry
      

  5.   

    double d=Double.parseDouble("415.230150");//为什么要写这么一条语句double d=415.230150;  //这样不也可以吗??