处理一位小数加逗号组成的字符串,每个数除10后再返回原类型字符串
public static void main(String[] args) {
String s = "0.4,0.5,0.5,0.7,0.7,0.9,0.9,0.2";
System.out.println(chushi(s));
}
public static String chushi(String str) {//字符串中的每个都除10再返回字符串
String newStr = "";
String[] str2 = str.split(",");// 分割成数组
String[] s= new String[str2.length];
for(int i=0;i<s.length;i++){
s[i]=String.format("%.2f", Float.parseFloat(str2[i])/10);
}//将字符串转换成浮点型,再保留两位小数
for(int i=0;i<s.length;i++){
if (i < s.length - 1)
newStr += s[i] + ",";
else{
newStr+= s[i];
}
}
return newStr;
}