Add Commas to numbers

Learn how to add commas to numbers

  1. Give the text a class
  2. 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>