- public String getPercent(int x,int total){
- String result="";//接受百分比的值
- double x_double=x*1.0;
- double tempresult=x/total;
- //NumberFormat nf = NumberFormat.getPercentInstance(); 注释掉的也是一种方法
- //nf.setMinimumFractionDigits( 2 ); 保留到小数点后几位
- DecimalFormat df1 = new DecimalFormat("0.00%"); //##.00% 百分比格式,后面不足2位的用0补齐
- //result=nf.format(tempresult);
- result= df1.format(tempresult);
- return result;
- }
JAVA中计算百分比
最新推荐文章于 2024-08-22 02:14:26 发布