Add Commas to numbers
Learn how to add commas to numbers
- Give the text a class
- Add the following snippet (make sure you change the class)
<script>
function addCommasToNumbers() {
var elements = document.getElementsByClassName("number-commas");
for (var i = 0; i < elements.length; i++) {
var number = parseInt(elements[i].textContent);
var formatter = new Intl.NumberFormat();
var numberWithCommas = formatter.format(number);
elements[i].textContent = numberWithCommas;
}
}
addCommasToNumbers();
<script>