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;
}
|