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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:27:08+00:00 2026-06-15T01:27:08+00:00

I use one small code js to add comma to value: function addCommas(nStr) {

  • 0

I use one small code js to add comma to value:

function addCommas(nStr)
{
    nStr += '';
    x = nStr.split('.');
    x1 = x[0];
    x2 = x.length > 1 ? '.' + x[1] : '';
    var rgx = /(\d+)(\d{3})/;
    while (rgx.test(x1)) {
        x1 = x1.replace(rgx, '$1' + ',' + '$2');
    }
    return x1 + x2;
}

I have problem when try to add comma to big values like sextillion values.
Eg.

addCommas(1000000) //return correct "1,000,000"

but if use big values like this

addCommas(50949024266983356472874) // return wrong "5.094902426698335e+22"

What or where I do wrong?

  • 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-15T01:27:09+00:00Added an answer on June 15, 2026 at 1:27 am

    If your number is stored in a string the following function will achieve what you are asking for.

    function addCommas( txtNum ) {
        var parts = txtNum.split(".");
        parts[0] = parts[0].reverse().replace(/(\d{3})/g, "$1,").reverse();
        return parts.join(".");
    }   
    
    String.prototype.reverse = function () {
        return this.split("").reverse().join("");
    }
    
    addCommas( "-50000000000000000000000000000000000000000.0000" );
    // => -50,000,000,000,000,000,000,000,000,000,000,000,000,000.0000
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We all do code, small (like one .exe) or big applications (complete solutions) with
In my code I use a small data-storing class, which is created in different
Here's a small code in one of my activities. Window window = this.getWindow(); window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
I need to add a key with a value that increases by one for
What technique shall one use to implement batch insert/update for Backbone.sync?
If I only ever use one Statement at a time would it be worthwhile
I want to use one program as a shared library for an other program.
The use case is that I use one development machine for different source trees.
I need to use one of the resourceful controllers plugins - resources_controller/ resource_controller/make_resourceful as
Is there a way I can use one category to stylize all of my

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.