c*y
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"?
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"?
KG
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,',');
【在 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,',');
相关阅读
Java interivew questions(10-30) Files on the ftp serverRe: Entity EJB: anyone with real experienceJMIT v0.0.001 ReleaseRe: cannot make JSSE work, faint!Re: 如何用java做skin.upload some materialsJMIT v0.1 UPDATEdatabase connection poolRe: DCOM, CORBA, JAVA/RMIMastering the classpath with JWhichJava Question 151-199(end)35 books by O'Reilly uploadedRe: strange exceptionA nice EJB server(recommend)Re: 关于APPLET的IO问题申请成立OOP俱乐部。(讨论稿)更好的使用googleRe: Expert, help me, please -Java Server Environment set upRe: connection pool