JSFiddle - React, Tailwind, and code Playground

by mattnuns

HTML

<p id='count_div'></p>

JavaScript

$.fn.digits = function(){ 
    return this.each(function(){ 
        $(this).text( $(this).text().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,") ); 
    })
}

var prev_count = '1,125';
prev_count = prev_count.split(',').join('');
prev_count = parseInt(prev_count);
alert(prev_count);

var new_count = 1020.50;

var count_till = prev_count < new_count ? new_count : new_count;
jQuery({ Counter: prev_count }).animate({ Counter: count_till }, {
    duration: 7000,
    easing: 'swing',
    step: function () {
    jQuery("#count_div").text(this.Counter.toFixed(2)).digits();

    }
});