1function addCommas(nStr){
2 nStr += '';
3 x = nStr.split('.');
4 x1 = x[0];
5 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}