String price = "1999123456.78";
StringBuffer sb = new StringBuffer(price);
// int index = sb.lastIndexOf(".");//获取字符在字符串中最后一次出现的索引,索引从0开始,//6
// System.out.println(index);
// sb= sb.insert(index - 3, ",");
// System.out.println(sb);
for (int i = sb.lastIndexOf(".") - 3; i > 0; i -= 3) {
sb = sb.insert(i , ",");
}
System.out.println(sb);
hspJava P478联系
最新推荐文章于 2024-07-23 21:45:09 发布