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)));