
获得徽章 0
使用ai code 时始终检测这块处理字符串 千分位时提示代码 处理逗号位置错误;public static String solution(String s) {
if(null == s || s.isEmpty()){
return s;
}
// 输入字符串分为小数部分和整数部分
String a ="";
String b = "";
if(s.contains(".")){
String[] arryStr = s.split("\\.");
a = arryStr[0];
b = "." + arryStr[1];
} else{
a = s;
}
while (a.startsWith("0")) {
a = a.substring(1);
}
StringBuilder sb = new StringBuilder();
int count = 0;
for(int i = a.length() - 1; i >= 0; i--){
sb.append(a.charAt(i));
count += 1;
if(0 != i && count == 3){
sb.append(",");
count = 0;
}
}
return sb.reverse() + b;
}
if(null == s || s.isEmpty()){
return s;
}
// 输入字符串分为小数部分和整数部分
String a ="";
String b = "";
if(s.contains(".")){
String[] arryStr = s.split("\\.");
a = arryStr[0];
b = "." + arryStr[1];
} else{
a = s;
}
while (a.startsWith("0")) {
a = a.substring(1);
}
StringBuilder sb = new StringBuilder();
int count = 0;
for(int i = a.length() - 1; i >= 0; i--){
sb.append(a.charAt(i));
count += 1;
if(0 != i && count == 3){
sb.append(",");
count = 0;
}
}
return sb.reverse() + b;
}
展开
5
点赞
赞了这篇文章
赞了这篇沸点
赞了这篇文章
赞了这篇文章
赞了这篇文章
赞了这篇文章
赞了这篇文章