Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8137065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T10:58:09+00:00 2026-06-06T10:58:09+00:00

Possible Duplicate: JavaScript: formatting number with exactly two decimals Can some one please help

  • 0

Possible Duplicate:
JavaScript: formatting number with exactly two decimals

Can some one please help me with my java script?
My java script consistently counts up, the problem is the cents character length is way too long (need 2 characters max). Another problem is, I don’t know what code additionally I need to put commas in the correct position for determining the proper amount. Example: 12345.67 vs 12,345.67. If some one can just take a look at the code, modify it and re-post the full code since I have no idea what to do, I would deeply appreciate it.

This is the javascript code: http://jsfiddle.net/pqsH6/


<p style="float:left;">Money Saved: </p><b><p id="ds"  style="float:left;">$</p></b>
<div id="counter" style="float:left;"></div>

<script type="text/javascript">
    var START_DATE = new Date("january 1, 2012 12:00:00"); // put in the starting date here   
    var INTERVAL = 1000; // savings per second
    var INCREMENT = 0.005; // money saved per second
    var START_VALUE = -50000; // configures proper savings calculation
    var count = 0;
    window.onload = function()
    {
        var msInterval = INTERVAL * 1;
        var now = new Date();
        count = parseInt((now - START_DATE)/msInterval) * INCREMENT + START_VALUE;
        document.getElementById('counter').innerHTML = count;
        setInterval("count += INCREMENT; document.getElementById('counter').innerHTML = count;", msInterval);
    }
</script>​
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T10:58:10+00:00Added an answer on June 6, 2026 at 10:58 am

    This looks like a way to format your output with commas using Javascript:

    How to print a number with commas as thousands separators in JavaScript

    function numberWithCommas(x) {
        return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
    }
    

    Just pass your numbers through the function as a parameter and it will return a comma delimited number.

    Here’s another function you can use to round out to two decimal places:

    function formatCurrency(num) {
        num = isNaN(num) || num === '' || num === null ? 0.00 : num;
        return parseFloat(num).toFixed(2);
    }
    

    Then use the function like this

    var roundedCurrencyAmt = numberWithCommas(formatCurrency(amtOfMoney));
    

    Here’s a working jsFiddle: http://jsfiddle.net/alexfromapex/Y2x8m/2/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: JavaScript: formatting number with exactly two decimals Now that I have got
Possible Duplicate: JavaScript: formatting number with exactly two decimals How do I limit the
Possible Duplicate: JavaScript: formatting number with exactly two decimals Maybe I'm going about this
Possible Duplicate: javascript substring How can I do substr (php) in JS? Example code
Possible Duplicate: JavaScript Pass Variables Through Reference How can you do something like this
Possible Duplicate: JavaScript equivalent to printf/string.format How can I create a Zerofilled value using
Possible Duplicate: Formatting a date in javascript I know other possible formats in JavaScript
Possible Duplicate: Javascript color gradient I have color one (let's say yellow) and color
Possible Duplicate: Javascript closure inside loops - simple practical example How can I make
Possible Duplicate: Javascript parseInt gives very unexpected results Can someone explain why javascript interprets

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.