Live Money/Currency Counter (US Debt Clock)

Hi. I'm looking for a script to count money up including cents. Exactly like this website: http://costofwar.com/en/state/AL/congdistrict/06/ except I need it fancier with images as numbers and a background.

For example: I set it to start from $1,030,301.01 and it should count up every second by whatever amount. Also, it cannot reset on reload and should be live no matter who sees the page.

Thank you.
lean0nmeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Michel PlungjanIT ExpertCommented:
So do you have something already and a server process that stores the current amount?
Or is this a Gimme-the-codez question?
0
lean0nmeAuthor Commented:
I guess it's a gimme-the-codez question lol.
0
Michel PlungjanIT ExpertCommented:
My email address is in my profile as well as a HIRE ME button
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

lean0nmeAuthor Commented:
Ok, let's try it this way if you could help I'd appreciate it. I have this code to do what I want, but I need to modify 2 things.

1. It gets the value using date. I want to specificy the value.
2. I want the numbers to be fancier and use images instead.

Could you help with those please? :)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 
<html>
<head>
	<title>Amount Incrementer</title>
	
	<script type="text/javascript">
		function calcAmount() {
		      var dateNow = new Date();
		      var dateStart = new Date();
			  var incAmount = .01; // change to the amount by which you wish to increment
		      dateStart.setDate(1);
		      dateStart.setMonth(0);
		      dateStart.setHours(0);
		      dateStart.setMinutes(0);
		      dateStart.setSeconds(0);
		      dateStart.setMilliseconds(0);
		      t = setTimeout(calcAmount, 1);
		      document.getElementById('amount').innerHTML = "$" + CurrencyFormatted(incAmount*parseInt((dateNow - dateStart)/(1000)));
		}
		
	// function for formatting numbers in currency format
	function CurrencyFormatted(amount)
	{
		var i = parseFloat(amount);
		if (isNaN(i)) {
			i = 0.00;
		}
		var minus = '';
		if (i < 0) { 
			minus = '-'; 
		}
		i = Math.abs(i);
		i = parseInt((i + .005) * 100);
		i = i / 100;
		s = new String(i);
		if (s.indexOf('.') < 0) { 
			s += '.00'; 
		}
		if (s.indexOf('.') == (s.length - 2)) { 
			s += '0'; 
		}
		s = minus + s;
		s = CommaFormatted(s)
		return s;
	}
	
	// function for formatting numbers with embedded commas
	function CommaFormatted(amount)
	{
		var delimiter = ","; // replace comma if desired
		var a = amount.split('.',2)
		var d = a[1];
		var i = parseInt(a[0]);
		if (isNaN(i)) { 
			return ''; 
		}
		var minus = '';
		if (i < 0) { 
			minus = '-'; 
		}
		i = Math.abs(i);
		var n = new String(i);
		var a = [];
		while(n.length > 3)
		{
			var nn = n.substr(n.length-3);
			a.unshift(nn);
			n = n.substr(0,n.length-3);
		}
		if (n.length > 0) { 
			a.unshift(n); 
		}
		n = a.join(delimiter);
		if (d.length < 1) { 
			amount = n; 
		} else { 
			amount = n + '.' + d; 
		}
		amount = minus + amount;
		return amount;
	}
	</script>
	
</head>
 
<body onload="calcAmount();">
 
Current amount is: <span id="amount"></span>
 
</body>
</html>

Open in new window

0
Michel PlungjanIT ExpertCommented:
Sure. I'll look tomorrow morning. NOW I'm off to celebrate my birthday.
0
lean0nmeAuthor Commented:
Thanks and Happy birthday!
0
Michel PlungjanIT ExpertCommented:
Thanks - I strongly advice against using images
Instead go wild with CSS.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 
<html>
<head>
  <title>Amount Incrementer</title>
<style type="text/css">
#amount { font-face:courier; font-weight:bold; color:teal; }
</style>  
  <script type="text/javascript">
  
  // function for formatting numbers in currency format
  function CurrencyFormatted(amount)
  {
    var i = parseFloat(amount);
    if (isNaN(i)) {
      i = 0.00;
    }
    var minus = '';
    if (i < 0) { 
      minus = '-'; 
    }
    i = Math.abs(i);
    i = parseInt((i + .005) * 100);
    i = i / 100;
    s = new String(i);
    if (s.indexOf('.') < 0) { 
      s += '.00'; 
    }
    if (s.indexOf('.') == (s.length - 2)) { 
      s += '0'; 
    }
    s = minus + s;
    s = CommaFormatted(s)
    return s;
  }
  
  // function for formatting numbers with embedded commas
  function CommaFormatted(amount)
  {
    var delimiter = ","; // replace comma if desired
    var a = amount.split('.',2)
    var d = a[1];
    var i = parseInt(a[0]);
    if (isNaN(i)) { 
      return ''; 
    }
    var minus = '';
    if (i < 0) { 
      minus = '-'; 
    }
    i = Math.abs(i);
    var n = new String(i);
    var a = [];
    while(n.length > 3)
    {
      var nn = n.substr(n.length-3);
      a.unshift(nn);
      n = n.substr(0,n.length-3);
    }
    if (n.length > 0) { 
      a.unshift(n); 
    }
    n = a.join(delimiter);
    if (d.length < 1) { 
      amount = n; 
    } else { 
      amount = n + '.' + d; 
    }
    amount = minus + amount;
    return amount;
  }
  var amount = 1030301.01; // load from server
  window.onload=function() {
    var delay = 100; // milliseconds    
    var incAmount = .01; // change to the amount by which you wish to increment
    var tId = setInterval(function() {
      document.getElementById('amount').innerHTML = "$" + CurrencyFormatted(amount+=incAmount);
    },delay)

  }
  </script>
  
</head>
 
<body>
 
Current amount is: <span id="amount"></span>
 
</body>
</html>

Open in new window

0
lean0nmeAuthor Commented:
Any reason to use CSS instead of images? I want it to have like a "flip style" counter.

Also, the counter shouldn't reset after reload and should be "live" with everyone seeing the same number like on the http://costofwar.com/en/state/AL/congdistrict/06/ website.

Thanks for the help!
0
Michel PlungjanIT ExpertCommented:
Yes, using images are VERY resource hungry when flipping - now we flip as ft as possible, with images we can perhaps flip once a second
It is up to you to have the page read the initial counter from a text file. It is not advisable to read the server counter more than once per page load.
You insert it where I suggested it
0
lean0nmeAuthor Commented:
Can you please elaborate on that? In order for me to have a live counter, I would have to write to a txt file and read it constantly, no? How could I make it do it once refresh?
0
Michel PlungjanIT ExpertCommented:
I do not know how precise this counter should be nor what the algorithm for the number. If it can be calculated, calculate it each time the page is loaded. If not have a script run on the server that updates a text file and read that file from the page that shows it to the user.

Otherwise WHO updates the counter? Each person that loads the page will call to the server every second or so? That could be very heavy.

Perhaps you tell me what exactly you are counting and how you get to that number and I can give better answers
0
lean0nmeAuthor Commented:
It's not calculating anything. Just takes a number from a .txt file and displays it is good enough. The file needs to be updated every second to increment the number and I just need that number to be consistent with everyone who views the page.

So basically I could create a php script to constantly update a .txt file and read that number with the script you provided? Any ideas for doing that?
0
Michel PlungjanIT ExpertCommented:
Sure
Not being a php guy I would change the bit where it says 1030301.01 to
<?php file_get("counter.txt"); ?>
0
lean0nmeAuthor Commented:
Thanks. I can write a php script to constantly update counter.txt though a loop every second or so but wouldn't that load the server too much? Also, where would I put the script in order for it to run constantly?
0
Michel PlungjanIT ExpertCommented:
What can I say?

You want a value that all who load your page will see. If you cannot calculate it in the script, then of course you need a server file

If you have thousand of hits a minute, you will need to create the file and read it into memory when your server starts, keep it there and occasionally write a copy to file in case you need to restart the server.

It is very basic http. If you want a value to persist and update, you will need to store the value somewhere. If you need it to persist across reboots, you need a file.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
lean0nmeAuthor Commented:
Thanks for all the help!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Scripting Languages

From novice to tech pro — start learning today.