s = "," + temp + s; } s = sss + s; System.out.println(s);
}
java.text.DecimalFormat df = new java.text.DecimalFormat("#,##0.00");System.out.println(df.format(1234567890));
import java.text.DecimalFormat;public class III { public static void main(String[] args) { DecimalFormat df = new DecimalFormat("#,###"); System.out.println(df.format(1234567890)); } }
同上 import java.text.DecimalFormat; public class Test1 { public static void main(String[] args) { double x; x=1234567890.890909; DecimalFormat df=new DecimalFormat(); System.out.println(df.format(x)); } }
{
StringBuffer sb=new StringBuffer();
sb.append(i);
int index=0;
if(sb.charAt(0)=='-')
index++;
while((index+=3)<sb.length())
{
sb.insert(index,',');
index++;
}
return sb.toString();
}
测试结果
f(1234567890) 123,456,789,0
f(-1234567890) -123,456,789,0
redduke1202(★及时结贴是一种美德★)
和
wangzhiqing(乱马1/2)
你自己选吧,正好是两种分割法.
to wangzhiqing(乱马1/2)
你的方法能实现"123,456,789,0"吗?
public static void main(String[] args) {
// TODO Auto-generated method stub int iii = 1234567890;
String sss = String.valueOf(iii);
String s = "", temp = "";
while(sss.length() > 3){
temp = sss.substring(sss.length() - 3);
sss = sss.substring(0, sss.length() - 3);
s = "," + temp + s;
}
s = sss + s;
System.out.println(s);
}
public static void main(String[] args) {
DecimalFormat df = new DecimalFormat("#,###"); System.out.println(df.format(1234567890));
}
}
import java.text.DecimalFormat;
public class Test1 {
public static void main(String[] args) {
double x;
x=1234567890.890909;
DecimalFormat df=new DecimalFormat();
System.out.println(df.format(x));
}
}