将程序中的double值精确到小数点后两位。能够四舍五入,也能够直接截断。html
好比:输入12345.6789,输出能够是12345.68也能够是12345.67。至因而否须要四舍五入,能够经过参数来决定(RoundingMode.UP/RoundingMode.DOWN等参数)。git
formatDouble1( ()Math.round(d*100)/100 formatDouble2( BigDecimal bg = BigDecimal(d).setScale(2 String formatDouble3(= nf.setMaximumFractionDigits(2 String formatDouble4(= DecimalFormat("#.00" String formatDouble5( String.format("%.2f" d = 12345.67890