方法Ⅰ:
System.out.printf("%.2f",x);
方法Ⅱ:
System.out.println(String.format("%.2f", x));
方法Ⅲ:
DecimalFormat decimalFormat = new DecimalFormat("#.00");
System.out.println(decimalFormat.format(f));
方法Ⅳ:
BigDecimal bigDecimal = new BigDecimal(f);
double x = bigDecimal.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
System.out.println(x);
方法Ⅴ:
double f = 111231.5585;
NumberFormat numberFormat = NumberFormat.getNumberInstance();
numberFormat.setMaximumFractionDigits(2);
System.out.println(numberFormat.format(f));