[Javascript] add commas to number js

HTML
<p id="commaNumber">303223000</p>
CSS
JAVASCRIPT
function addCommas(n){ var rx= /(\d+)(\d{3})/; return String(n).replace(/^\d+/, function(w){ while(rx.test(w)){ w= w.replace(rx, '$1,$2'); } return w; }); } var commaNumber = document.getElementById("commaNumber"); commaNumber.textContent = addCommas(commaNumber.textContent);
Expand for more options Login