求两个数的百分比

    1.   int num1 = 7;  
    2.   
    3.         int num2 = 9;  
    4.   
    5.         // 创建一个数值格式化对象  
    6.   
    7.         NumberFormat numberFormat = NumberFormat.getInstance();  
    8.   
    9.         // 设置精确到小数点后2位  
    10.     
    11.         numberFormat.setMaximumFractionDigits(2);  
    12.   
    13.         String result = numberFormat.format((float) num1 / (float) num2 * 100);  
    14.   
    15.         System.out.println("num1和num2的百分比为:" + result + "%"); 
原文地址:https://www.cnblogs.com/withoutaword/p/8822549.html