int num1 = 500;  
        int num2 = 312;  
  
        // 创建一个数值格式化对象  
        NumberFormat numberFormat = NumberFormat.getInstance();
  
        // 设置精确到小数点后2位  
        numberFormat.setMaximumFractionDigits(2);  
  
        String result = numberFormat.format((float) num1 / (float) num2 * 100);  

        System.out.println("num1和num2的百分比为:" + result + "%");  
     结果为:62.4%        

 

相关文章:

  • 2021-12-28
  • 2022-12-23
  • 2021-12-24
  • 2022-12-23
  • 2022-12-23
  • 2021-12-25
  • 2021-12-15
  • 2021-11-15
猜你喜欢
  • 2022-01-31
  • 2021-12-26
  • 2021-12-25
  • 2021-12-25
  • 2022-12-23
  • 2022-12-23
  • 2021-11-16
相关资源
相似解决方案