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找工作需要degree吗?除了core spring,还有spring的啥sub project应该会呢October Headline: Dart enters the top 20 for the first time (转载)Spring JBOSS为什么Arrays.asList()不做autoboxing?bad news:Oracle wins, Google loses in copyright ruling on Java APIs需要学习Groovy吗?这个比Java到底好在什么地方java架构问题最好的前台开发动态网站的javascript library?Java 问题这个UDDI是咋回事儿?求讲解。。。java concurrency (转载)老板问想不想考什么证,公司可以付钱 (转载)怎么练习java multithreadJAVA 求解迷茫的小弟,还有半年社区大学毕业,求建议。。谢谢CS在读Master新生怎么找JAVA Intern?C#转Java新手码农求助,如何能快速积累Java编程经验java custom utility库函数的数据库?Project Panama builds a bridge between Java and C/C++