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 297953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T06:41:14+00:00 2026-05-12T06:41:14+00:00

I am trying to increment a number by a given value each second and

  • 0

I am trying to increment a number by a given value each second and retain the formatting using JavaScript or JQuery

I am struggling to do it.

Say I have a number like so:

1412015

the number which this can be incremented by each second is variable it could be anything beween 0.1 and 2.

Is it possible, if the value which it has to be incremented by each second is 0.54 to incremenet the number and have the following output:

1,412,016
1,412,017
1,412,018

Thanks

Eef

  • 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-05-12T06:41:14+00:00Added an answer on May 12, 2026 at 6:41 am

    I’m not quite sure I understand your incrementation case and what you want to show.
    However, I decided to chime in on a solution to format a number.

    I’ve got two versions of a number format routine, one which parses an array, and one which formats with a regular expression. I’ll admit they aren’t the easiest to read, but I had fun coming up with the approach.

    I’ve tried to describe the lines with comments in case you’re curious

    Array parsing version:

    function formatNum(num) {
        //Convert a formatted number to a normal number and split off any 
        //decimal places if they exist
        var parts = String( num ).replace(/[^\d.]-/g,'').split('.');
        //turn the string into a character array and reverse
        var arr = parts[0].split('').reverse();
    
        //initialize the return value
        var str = '';
    
        //As long as the array still has data to process (arr.length is 
        //anything but 0)
        //Use a for loop so that it keeps count of the characters for me
        for( var i = 0; arr.length; i++ ) {
            //every 4th character that isn't a minus sign add a comma before 
            //we add the character
            if( i && i%3 == 0 && arr[0] != '-' ) {
                str  = ',' + str ;
            }
    
            //add the character to the result
            str  = arr.shift() + str ;
        }
    
        //return the final result appending the previously split decimal place 
        //if necessary
        return str + ( parts[1] ? '.'+parts[1] : '' );
    }
    

    Regular Expression version:

    function formatNum(num) {
        //Turn a formatted number into a normal number and separate the 
        //decimal places
        var parts = String( num ).replace(/[^\d.]-/g,'').split('.');
        //reverse the string
        var str = parts[0].split('').reverse().join('');
        //initialize the return value
        var retVal = '';
    
        //This gets complicated. As long as the previous result of the regular 
        //expression replace is NOT the same as the current replacement, 
        //keep replacing and adding commas.
        while( retVal != (str = str.replace(/(\d{3})(\d{1,3})/,'$1,$2')) ) {
            retVal = str;
        }
    
        //If there were decimal points return them back with the reversed string
        if( parts[1] ) {
            return retVal.split('').reverse().join('') + '.' + parts[1];
        }
    
        //return the reversed string
        return retVal.split('').reverse().join('');
    }
    

    Assuming you want to output a formatted number every second incremented by 0.54 you could use an interval to do your incrementation and outputting.

    Super Short Firefox with Firebug only example:

    var num = 1412015;
    
    setInterval(function(){
        //Your 0.54 value... why? I don't know... but I'll run with it.
        num += 0.54;
        console.log( formatNum( num ) );
    },1000);
    

    You can see it all in action here: http://jsbin.com/opoze

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

Sidebar

Ask A Question

Stats

  • Questions 215k
  • Answers 215k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Have a look at the language services packages, particularly the… May 12, 2026 at 10:59 pm
  • Editorial Team
    Editorial Team added an answer Shader uniforms are typically implemented by the hardware as registers… May 12, 2026 at 10:59 pm
  • Editorial Team
    Editorial Team added an answer You could use MediaStreamSource instead of MediaFileSource. May 12, 2026 at 10:59 pm

Related Questions

My question is how to get the number of rows returned by a query
just trying to tie up a few loose odds and ends here. I have
This is a follow up on another problem i had with getting-the-last-record-inserted-into-a-select-query I am
I'm trying to write a simple raytracer as a hobby project and it's all

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.