每隔三位添加一个逗号(小数点/整数都适合)

 1  addCommas:function(nStr)
 2     {
 3         nStr += '';
 4         x = nStr.split('.');
 5         x1 = x[0];
 6         x2 = x.length > 1 ? '.' + x[1] : '';
 7         var rgx = /(\d+)(\d{3})/;
 8         while (rgx.test(x1)) {
 9         x1 = x1.replace(rgx, '$1' + ',' + '$2');
10         }
11         return x1 + x2;
12     }

来自于网络

posted on 2018-08-06 15:50  HMirror  阅读(363)  评论(0编辑  收藏  举报