I am trying to add commas (thousand separator) for big numbers that use the follow counter function:
<script type='text/javascript'>
$(window).load(function() {
$('.Count').each(function() {
var $this = $(this);
jQuery({Counter: 0}).animate({Counter: $this.text()}, {
duration: 1500,
easing: 'swing',
step: function() {
$this.text(Math.ceil(this.Counter));
}
});
});
});
Do I modify this particular formula or do I have to write an additional function that will handle the formatting?
this might work
<script>
$(window).load(function() {
$('.Count').each(function() {
var $this = $(this);
jQuery({Counter: 0}).animate({Counter: $this.text()}, {
duration: 1500,
easing: 'swing',
step: function() {
var num = Math.ceil(this.Counter).toString();
if(Number(num) > 999){
while (/(\d+)(\d{3})/.test(num)) {
num = num.replace(/(\d+)(\d{3})/, '$1' + ',' + '$2');
}
}
$this.text(num);
}
});
});
});
</script>
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments