-2

I've tried a few solutions from Stack Overflow but I cannot for the life of me figure out how to add comma separators to the counts as seen in this fiddle.

HTML

Today: <div id="count"></div><br/>
This Year: <div id="yearcount"></div>

Javascript

var div = document.getElementById('count');
var yeardiv = document.getElementById('yearcount');



function updateCount(wid) {
    var d = new Date();
    // set d to midnight
    d.setHours(0,0,0,0);
    var count = Math.floor( ( new Date().getTime() - d.getTime() ) / 8000 );
    div.innerHTML = count;
    var wid = count;

    // set d to Jan 1st
    d.setMonth( 0 );
    d.setDate( 1 );
    count = Math.floor( ( new Date().getTime() - d.getTime() ) / 8000 )
    yeardiv.innerHTML = count;

}
updateCount();
setInterval( updateCount, 8000 );

Any help would be greatly appreciated, thank you all in advance!

1 Answers1

2

You could use toLocaleString, as in:

yeardiv.innerHTML = count.toLocaleString();

Updated Fiddle: http://jsfiddle.net/abhitalks/dzae4715/4/

Reference: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString

.

Abhitalks
  • 27,721
  • 5
  • 58
  • 81