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