k*o 发帖数: 46 | 1 how to transform int 1000 to "1,000" instead of "1000"? | c*y 发帖数: 137 | 2 You can write an toComaString function to do that easily.
This is one I came up:
public static String toCommaString(int i){
String s=String.valueOf(i);
int l=s.length();
if(l <= 3) return s;
StringBuffer sb=new StringBuffer(s);
int ll=l-3;
while (ll>0){
sb.insert(ll,',');
ll=ll-3;
}
return sb.toString();
}
【在 k*o 的大作中提到】 : how to transform int 1000 to "1,000" instead of "1000"?
| d******p 发帖数: 24 | 3 java.txt.DecimalFormat can do it and much more.
【在 k*o 的大作中提到】 : how to transform int 1000 to "1,000" instead of "1000"?
| KG 发帖数: 515 | 4 A better way to do it is to use NumberFormat, taking into account the Locale.
【在 c*y 的大作中提到】 : You can write an toComaString function to do that easily. : This is one I came up: : public static String toCommaString(int i){ : String s=String.valueOf(i); : int l=s.length(); : if(l <= 3) return s; : StringBuffer sb=new StringBuffer(s); : int ll=l-3; : while (ll>0){ : sb.insert(ll,',');
|
|