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 }
来自于网络