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

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-07-02
  • 2022-12-23
  • 2021-06-05
  • 2022-12-23
  • 2022-12-23
  • 2021-11-20
相关资源
相似解决方案