Small error - should be
var count = parseInt((now.getTime() - START_DATE.getTime())/
INTERVAL) * INCREMENT + START_VALUE;
Old Pedant's code will only insert commas up to $999,999.99. If you need bigger than that:-
Code:
<script type="text/javascript">
// works with negative numbers also
function formatNumber(x) {
return x.toFixed(2).split('').reverse().join('').replace(/(?=\d*\.?)(\d{3})/g,'$1,').split('').reverse().join('').replace(/^[\,]/,'');
}
var num = formatNumber(1234567.8897);
num = "$" + num;
alert (num);
</script>
or add to Old Pedant's code to extend to 999999999.99
Code:
if ( pretty.length > 10 ) {
pretty = pretty.substring(0,pretty.length-10) + "," + pretty.substring(pretty.length-10);
}