试试看这个:
这个是显示的时候保留4位显示import java.text.*;
.......... double price = 0.684000000003;
DecimalFormat df = new DecimalFormat( ".####");
System.out.println( df.format( price ) ); ..........

解决方案 »

  1.   

    System.out.println(new java.text.DecimalFormat("#.0000").format(price));
      

  2.   

    public double MyFormat(double d)
        {
            String s = "##.0000";
            DecimalFormat decimalformat = new DecimalFormat(s);
            String s1 = decimalformat.format(d);
            double d1 = Double.parseDouble(s1);
            return d1;
        }