I am trying to print an number in JavaScript with commas as separators. but when i add comma it will give me Nan value For example, I want to show the number 170607 as "170,607". How would I go about doing this?
HTML :
- <div class="row about-stats stats block-1-4 block-m-1-2 block-mob-full" data-aos="fade-up">
- <div class="col-block stats__col ">
- <div class="stats__count">4</div>
- </div>
- <div class="col-block stats__col">
- <div class="stats__count">40</div>
- </div>
- <div class="col-block stats__col">
- <div class="stats__count">170607</div>
- </div>
- <div class="col-block stats__col">
- <div class="stats__count">3447</div>
- </div>
- </div>
Script:
-
-
- var clStatCount = function() {
- var statSection = $(".about-stats"),
- stats = $(".stats__count");
- statSection.waypoint({
- handler: function(direction) {
- if (direction === "down") {
- stats.each(function () {
- var $this = $(this);
- $({ Counter: 0 }).animate({ Counter: $this.text() }, {
- duration: 4000,
- easing: 'swing',
- step: function (curValue) {
- $this.text(Math.ceil(curValue));
- }
- });
- });
- }
-
- this.destroy();
- },
- offset: "90%"
- });
- };