Click here to Skip to main content
12,622,895 members (31,555 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

10.2K views
4 bookmarked
Posted

Real-Time Ticker Showing Your Government's Cash Burn Rate

, 16 Feb 2015 CPOL
Rate this:
Please Sign up or sign in to vote.
Essentially the same code snippet with just a little bit cleaner and more efficient code1. setTimeout() is replaced with setInterval() function2. The interval is correctly set to 333 msec to produce 3 updates per second as specifiedRelated application (as FYI): Inflation...
Essentially the same code snippet with just a little bit cleaner and more efficient code

1. setTimeout() is replaced with setInterval() function
2. The interval is correctly set to 333 msec to produce 3 updates per second as specified
 
Related application (as FYI): Inflation Calculator[^]
 

<html>
<head>
     <script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.5.1.js" type="text/javascript"></script>
</head>
<body>
    <div id="counter"></div>
 
<script type="text/javascript">
    // capture the date parts we need for the calculation
    var currentyear = new Date().getFullYear();
    var startDateTicks = new Date(currentyear, 0, 1).getTime();
 
    // replace this with the ID of the element that is used to
    // display your burnt money total
    var $burnedMoneyElement = $("#counter");
 
    // replace this with your government's annual budget
    var governmentBudget = 13265000000;
 
    // figure out the per-second burn rate
    var moneyMultiplier = (((governmentBudget / 365) / 24) / 60) / 60;
 

    $(document).ready(function(){
    // this is called when the page is fully loaded
    // use setInterval() function to update the reading about 3 times a second
     setInterval("updateBurnedMoneyTicker()", 333);
   });
 
    // show me the money!!
    function updateBurnedMoneyTicker() {
        var curDateTicks = new Date().getTime();
        var totalVal = 0;
        // ticks are in milliseconds, compute by the second
        totalVal = (curDateTicks - startDateTicks);
        totalVal = totalVal / 1000;
        totalVal = totalVal * moneyMultiplier;
        $burnedMoneyElement.html(formatCurrency(totalVal));
    }
 
    // this currency formatting function is 
    // from http://javascript.internet.com
    function formatCurrency(num) {
        num = num.toString().replace(/\$|\,/g, '');
        if (isNaN(num))
            num = "0";
        sign = (num == (num = Math.abs(num)));
        num = Math.floor(num * 100 + 0.50000000001);
        cents = num % 100;
        num = Math.floor(num / 100).toString();
        if (cents < 10)
            cents = "0" + cents;
        for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++)
            num = num.substring(0, num.length - (4 * i + 3)) + ',' +
            num.substring(num.length - (4 * i + 3));
        return (((sign) ? '' : '-') + '$' + num + '.' + cents);
    } // end of code from http://javascript.internet.com
</script>
</body></html>

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

DrABELL
President Infosoft International Inc
United States United States
Dr. A. Bell is a full-stack software developer (Win/Web/Mobile). He holds PhD in EE/IT, published 300+ articles, authored 37 inventions and is credited for 10+ Enterprise level projects; currently focused on HTML5/CSS3, Javascript/jQuery, .NET/WPF/C#, Android/Angular.js, 'Big Data', AI, IoT. Alex participated in App Innovation Contests (AIC 2102/2013) with multiple winning submissions. Sample projects/pubs:
  1. Real-time NY Bus monitoring app (IoT)
  2. Semaphon™ semantic phone num-to-text converter
  3. Educational Web Portal
  4. Free Online NY Payroll Tax Calculator
  5. WebTV powered by Embedded YouTube Player (Goog #1 YouTube API for ASP.NET)
  6. Top-50 Digital Cameras (powered by iMark-DCAM rating engine)
  7. Pure CSS3 Slide Show
  8. Inflation Calculator
  9. CSS3 Modal Pop-up Dialog
  10. Multilingual Geocoder with Interactive Map
  11. Online Semantic Analyzer (Concordance Calculator)
  12. NY City Job Market and Agency Ratings
  13. Advanced CSS3 Table Formatting

You may also be interested in...

Comments and Discussions

 
GeneralHi Mr. James, Thanks for this clarification. In order to rea... Pin
DrABELL21-Mar-11 7:02
memberDrABELL21-Mar-11 7:02 
GeneralReason for my vote of 5 thanks for the review! Pin
TheyCallMeMrJames20-Mar-11 12:26
memberTheyCallMeMrJames20-Mar-11 12:26 
Generallol...yeah, in the body of the tip i had 333 in there too. i... Pin
TheyCallMeMrJames20-Mar-11 12:25
memberTheyCallMeMrJames20-Mar-11 12:25 
GeneralRe: Hi Mr. James, Thanks for this clarification. In order to r... Pin
DrABELL21-Mar-11 7:04
memberDrABELL21-Mar-11 7:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.161128.1 | Last Updated 16 Feb 2015
Article Copyright 2011 by DrABELL
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid