java,php,asp.net,linux,javascript,mysql,mssql,oracle,编程

计算百分比

转载请注明:http://www.pmjava.com/Article/ShowInfo.asp?ID=56616
private static String getRate(int success,int count){
        String rate
="0.00%";
       
if(count!=0){
            rate
=(double)success/count+"";
           
if(success/count>=1){
                rate
=rate.replace(".","");
               
if(rate.length()<6){
                   
while(rate.length()<=6){
                        rate
=rate+"0";
                    }
                    rate
=rate.substring(0,3)+"."+rate.substring(3, 5)+"%";
                }
else {
                   
if(Integer.parseInt(rate.charAt(5)+"")>=5){
                        rate
=rate.substring(0,3)+"."+rate.substring(3, 4)
                           
+(Integer.parseInt(rate.charAt(5)+"")+1)+"%";
                    }
else{
                        rate
=rate.substring(0,3)+"."+rate.substring(3, 5)+"%";
                    }
                }
            }
else{
               
if(rate.length()<6){
                   
while(rate.length()<=6){
                        rate
=rate+"0";
                    }
                    rate
=rate.substring(2,4)+"."+rate.substring(4, 6)+"%";
                }
else {
                   
if(Integer.parseInt(rate.charAt(5)+"")>=5){
                        rate
=rate.substring(2,4)+"."+rate.substring(4, 5)
                           
+(Integer.parseInt(rate.charAt(5)+"")+1)+"%";
                    }
else{
                        rate
=rate.substring(2,4)+"."+rate.substring(4, 6)+"%";
                    }
                }
            }
        }
       
       
return rate;
    }

posted on 2009-06-10 21:44 rrong_m 阅读(209) 评论(0)  编辑  收藏

<2024年11月>
272829303112
3456789
10111213141516
17181920212223
24252627282930
1234567

导航

统计

常用链接

随笔档案

文章分类

文章档案

java编程

搜索

积分与排名

最新评论

阅读排行榜

评论排行榜