把 int 1234567890 改称 123,456,789,0 这样的字符串

解决方案 »

  1.   

    从第一个开始,每3个数字插入一个逗号?String f(int i)
    {
             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
      

  2.   

    上面的 错了 应该是从后面开始 把 int 1234567890 改称 1,234,567,890 这样的字符串
      

  3.   

    你说明白啊.
    redduke1202(★及时结贴是一种美德★) 

    wangzhiqing(乱马1/2)
    你自己选吧,正好是两种分割法.
    to wangzhiqing(乱马1/2)
    你的方法能实现"123,456,789,0"吗?
      

  4.   

    好像是 这样的意思
    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);

    }
      

  5.   

    java.text.DecimalFormat df = new java.text.DecimalFormat("#,##0.00");System.out.println(df.format(1234567890));
      

  6.   

    import java.text.DecimalFormat;public class III {
    public static void main(String[] args) {
    DecimalFormat df = new DecimalFormat("#,###"); System.out.println(df.format(1234567890));
    }
    }
      

  7.   

    同上
    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));
        }
    }
      

  8.   

    DecimalFormat这个类是个格式数字的类。。是个不错的类学习