java 求 两个数的百分比% (转)


 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 + "%");  

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM