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

  • Home
  • SEARCH
  • 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 7022981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:39:08+00:00 2026-05-27T23:39:08+00:00

Situation: I have a calculator that I’m developing using these formulas: // — Math

  • 0

Situation:
I have a calculator that I’m developing using these formulas:
// — Math —

function national(){
        x = Number($('#budget').val());
        y = Number($('#percentage').val());

        a = x * 2;
        b = [x*(100/100-(1/y))]*2;
        c = (x*(1/y))*4;
        d = (b+c)-a;
        e = (d/a)*100;
        f = (b+c);

        $('#one').text(Math.round(a));
        $('#two').text(Math.round(b));
        $('#three').text(Math.round(c));
        $('#four').text(Math.round(d));
        $('#five').text(Math.round(e));
        $('#six').text(Math.round(f));

        $('#input1').text(Math.round(y));
        $('#input2').text(Math.round(x)); 


    }

I can’t change the formatting too much because I’m using this structure use a var as a pseudo-array to feed a bar graph plugin that graphically depicts my calculations.

I have used the Math.round action to eliminate crazy calculations, but I need to add numerical formatting to the output.

I was using this regex to inset my commas

Number.prototype.format = function (f) {
    return this.toString().split( /(?=(?:\d{3})+(?:\.|$))/g ).join( "," );
// ex $('#one').text(a.format());
};

but I don’t know how to incorporate the regex AND Math.round action…they keep killing each other.

Problem:
I need to format both my output DOM objects and my text input fields. Is this even possible and my syntax simply not appropriate, any input or possible solutions would be appreciated.

Bonus:
I’m using jQuery to perform my calculations which are being dumped into spans, if there is a proper solution, could I not only incorporate said solution in my output spans, but my input text fields as well?

Cheers.

  • 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-27T23:39:09+00:00Added an answer on May 27, 2026 at 11:39 pm

    Use this:

    Number.prototype.format = function () {
        return this.toString().replace(/(\d)(?=(\d{3})+$)/g, '$1,');
    };
    

    Then you could just call .format() after rounding:

    $('#one').text(Math.round(a).format());
    $('#two').text(Math.round(b).format());
    $('#three').text(Math.round(c).format());
    $('#four').text(Math.round(d).format());
    $('#five').text(Math.round(e).format());
    $('#six').text(Math.round(f).format());
    
    $('#input1').text(Math.round(y).format());
    $('#input2').text(Math.round(x).format());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following situation: I have a certain function that runs a loop
Situation: I have a calculator that I am building with js. It is a
Situation: I have a simple XML document that contains image information. I need to
I have situation, where running a query that filters by an indexed column in
Situation: I am writing a program in C that maintains a number of threads.
So here is the situation - I have a store app that I want
I have this situation that I need to let users define decisions based on
I have a small calculator that I am creating in C# (Sharp Develop). The
Let's say I have a situation like so: $(window).load(function() { $(body).append(<div id='container'></div>); var i=1;
Here's the situation: I have a predetermined GPS route that the user will run.

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.