java 小数点取2位并且四舍五入

BigDecimal bd = new BigDecimal(0.0199999999999);
System.out.println("res:"+bd.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
         DecimalFormat df = new DecimalFormat("#.00");
System.out.println(df.format(Double.parseDouble(str)));
System.out.println("=================");
System.out.println(String.format("%.2f", Double.parseDouble(str)));
System.out.println("=================");
NumberFormat nf = NumberFormat.getNumberInstance();
nf.setMaximumFractionDigits(2);
System.out.println(nf.format(Double.parseDouble(str)));
上一篇:C扩展Python


下一篇:CLR、程序集、反射和控制反转