Double保留两位小数

方式一:

String result = String .format("%.2f",double);

方式二:

NumberFormat ddf1=NumberFormat.getNumberInstance() ;

void setMaximumFractionDigits(int digits)

方式三:

double  f  =  111231.5585;

BigDecimal   b   =   new   BigDecimal(f);

double   f1   =   b.setScale(2,   BigDecimal.ROUND_HALF_UP).doubleValue();

方式四:

java.text.DecimalFormat  df  =new  java.text.DecimalFormat("#.00");

df.format(你要格式化的数字);

你可能感兴趣的:(Double保留两位小数)