import java.text.*;
public class number {
  public static void main(String args[]) {
    double d = 2/3;
    DecimalFormat df = new DecimalFormat("###,##0.000");
    System.out.println(df.format(d));
    }
  }

解决方案 »

  1.   

    to: skyyoung(路人甲),
        Double D = new Double(2/3)的D怎样转换成
        带三位小数double?
      

  2.   

    路人甲不是说得很清楚了吗?格式化一下Double就可以了
    DecimalFormat df = new DecimalFormat("###,##0.000");
    你可以改变"###,##0.000"成你想要的任何形式!
      

  3.   

    你可能是想得到3位小数的Double吧!Sorry!
    import java.text.*;
    public class number {
      public static void main(String args[]) {
        double d = 2/3;
        DecimalFormat df = new DecimalFormat("###,##0.000");
        Double d2 = new Double(df.format(d));
       /* 这样d2不就是3位小数的Double了吗?****/    
        }
      }
      

  4.   

    to: skyyoung(路人甲):
        我是说值的精度。你的程序的结果是0.000
        而不是我想要的0.667
        
      

  5.   

    import java.text.*;
    public class number {
      public static void main(String args[]) {
        double d = (double)2/3;
        DecimalFormat df = new DecimalFormat("###,##0.000");
        Double d2 = new Double(df.format(d));
      /* 这样d2不就是3位小数的Double了吗?****/    
        }
      }
      

  6.   

    to Virginer() :
       我在上面不是说得很清楚了吗?老兄能不能好好的看看别人的解答啊?
       Double d2 = new Double(df.format(d));
       上面的代码不就把你要的精度构造出来了吗?