Wednesday, 14 August 2013

Javascript: Adding comma to number

Javascript: Adding comma to number

When the number reaches 1000 it adds the comma and becomes like so 1,000
although once it implements the ',' it then resets back to 12 where it
should carry on.
Here is my jsFiddle: http://jsfiddle.net/m9cey/3/
var millisecs = 1000;
setInterval(function() {
var $badge = $('#badge');
var num = parseInt($badge.text())+11;
$badge.text(num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","));
}, millisecs);
Any help will be much appreciated.
Cheers

No comments:

Post a Comment