试试看这个:
这个是显示的时候保留4位显示import java.text.*;
.......... double price = 0.684000000003;
DecimalFormat df = new DecimalFormat( ".####");
System.out.println( df.format( price ) ); ..........
这个是显示的时候保留4位显示import java.text.*;
.......... double price = 0.684000000003;
DecimalFormat df = new DecimalFormat( ".####");
System.out.println( df.format( price ) ); ..........
{
String s = "##.0000";
DecimalFormat decimalformat = new DecimalFormat(s);
String s1 = decimalformat.format(d);
double d1 = Double.parseDouble(s1);
return d1;
}