0

I am trying to animate numbers to count up to the number specified in a div. This works but I would like the number to include the necessary commas. For example 62000000 should display as 62,000,000 - is there a way to do this by adding the commas to the numbers in my div or by having js add the commas automatically? Demo http://jsfiddle.net/FbkpM/

$(function(){
    var current = 0;
    var finish = jQuery('#statAssistance .statNum').text();
    var miliseconds = 3000;
    var rate = 100000;

    var counter = setInterval(function(){
         if(current >= finish) clearInterval(counter);
         $("#statAssistance .statNum").text("$" + current);
         current = parseInt(current) + parseInt(rate);
    }, miliseconds / (finish / rate));
});
karthikr
  • 97,368
  • 26
  • 197
  • 188
DevKev
  • 5,714
  • 6
  • 24
  • 29
  • 1
    While not *money*, you can use the same solution - [How can I format numbers as money in JavaScript?](http://stackoverflow.com/questions/149055/how-can-i-format-numbers-as-money-in-javascript). Always remember that **jQuery *is* JavaScript**. – Jason McCreary Jul 15 '13 at 19:24
  • What's a jQuery number? – cadrell0 Jul 15 '13 at 19:24
  • 1
    This has been answered already. Check here. http://stackoverflow.com/questions/1990512/add-comma-to-numbers-every-three-digits-using-jquery – Jay Patel Jul 15 '13 at 19:28
  • Thanks, though not sure how to implement this with my already existing js. Can you refactor my jsFiddle? – DevKev Jul 15 '13 at 19:35

0 Answers0