金钱数字转换成美式的有分隔符的样子

public static String formatLong(Long value) {
String str = value.toString();
StringBuffer strb = new StringBuffer(str);
StringBuffer outStr = new StringBuffer();
int start =0;
int len = strb.length();
int ys=len%3;
while((start+1)<=len){
if(ys==0){
ys=3;
}
outStr.append(strb.subSequence(start, ys+start));
outStr.append(",");
start = start + ys;
ys=3;
 
}
if (outStr.charAt(outStr.length() - 1) == ',') {
outStr = new StringBuffer(outStr.subSequence(0,
(outStr.length() - 1)));
}
return outStr.toString();
}
posted on 2013-06-24 15:14  Newzq  阅读(114)  评论(0)    收藏  举报