在线等待啊,或者QQ:53375176
mail:[email protected]

解决方案 »

  1.   

    <script>
    function comma(v){
    var re=/(\d+)(\d{3})/,s=v.toString();
    while(re.test(s))s=s.replace(re,"$1,$2");
    return s;
    }
    alert(comma(12345678.123));
    </script>
      

  2.   

    fason:
    不行啊,效果如下<html>
    <head>
    <script>
    function comma(v){
    var re=/(\d+)(\d{3})/,s=v.toString();
    while(re.test(s))s=s.replace(re,"$1,$2");
    return s;
    }
    function show(o){
    o.value=comma(o.value);
    }
    </script>
    </head>
    <body>
    <input type="text" name="txt" onkeyup="show(txt)">
    </dody>
    </html>
    </html>
    离完美还差两步
      

  3.   

    fason:
    不行啊,效果如下<html>
    <head>
    <script>
    function comma(v){
    var re=/(\d+)(\d{3})/,s=v.toString();
    while(re.test(s))s=s.replace(re,"$1,$2");
    return s;
    }
    function show(o){
    o.value=comma(o.value);
    }
    </script>
    </head>
    <body>
    <input type="text" name="txt" onkeyup="show(txt)">
    </dody>
    </html>
    </html>
    离完美还差两步
      

  4.   

    <html>
    <body>
    <script>
    function f(v)
    {
    var re=/(\d+)(\d{3})/,s=v.toString();
    while(re.test(s))s=s.replace(re,"$1,$2");
    return s;
    }var str=100000000.035;
    str=str.toFixed(2);
    var res=str.substr(str.indexOf(".")+1,2);
    str=str.substr(0,str.length-3);
    str=f(str);
    str=str+"."+res;
    alert(str);
    </script>
    </body>
    </html>
      

  5.   

    最简单的方法就是:var n = 100000000.035;
    execScript('n = FormatNumber("'+ n +'")','vbscript');
    alert(n);不过要IE5.0+
      

  6.   

    <script>
    var n = 100000000.035;
    alert(n.toLocaleString());
    </script>
      

  7.   

    <script>
    var num = "123456789.123";function c(tmp)
    {
    var parts = tmp.split("."); var intPart = parts[0];
    var dIntPart = (intPart.split("")).reverse();
    var dIntString = dIntPart.join("");
    var resultPart = dIntString.replace(/(.{3})(?=[^$])/g,"$1,");
    return resultPart.split("").reverse().join("")+"."+parts[1];
    }alert(c(num));
    </script>
      

  8.   

    用Number对象的toLocaleString方法会对小数位舍入,保留两位。
      

  9.   

    <html>
    <head>
    <script>
    function comma(v){
      v = v.replace(/,/g,"");
      var ar = v.split(".");
      var s = ar[0];
      var d = "";
      var re=/(\d+)(\d{3})/;
      while(re.test(s))
        s=s.replace(re,"$1,$2");
      if(ar.length>1)
        return s+"."+ar[1];
      return s;
    }
    function show(o){
    o.value=comma(o.value);
    }
    </script>
    </head>
    <body>
    <input type="text" name="txt" onkeyup="show(txt)">
    </dody>
    </html>
    </html>
      

  10.   

    OK,写的不错,我在前台已经用fason的方法实现了。
    在JAVA里怎么实现去逗号、加逗号函数?