My add thousands comma function doesnt workIs there an “exists” function for jQuery?How do JavaScript closures work?Add table row in jQueryvar functionName = function() vs function functionName() How does JavaScript .prototype work?Set a default parameter value for a JavaScript functionHow to print a number with commas as thousands separators in JavaScriptIs there a standard function to check for null, undefined, or blank variables in JavaScript?How can I add new array elements at the beginning of an array in Javascript?How does data binding work in AngularJS?

Wait or be waiting?

Who determines when road center lines are solid or dashed?

How to tell if JDK is available from within running JVM?

Align the contents of a numerical matrix when you have minus signs

Why did my "seldom" get corrected?

Are more expensive chains/casettes more quiet?

Making a Dataset that emulates `ls -tlra`?

What is actually sent/loaded to a microcontroller / stm32

Could a US citizen born through "birth tourism" become President?

Why is Google approaching my VPS machine?

How did Jayne know when to shoot?

Three Subway Escalators

Why isn't a binary file shown as 0s and 1s?

How can I help our ranger feel special about her beast companion?

"This used to be my phone number"

Do medium format lenses have a crop factor?

Why is the Intel 8086 CPU called a 16-bit CPU?

Real orthogonal and sign

Which failed attempts have there been to find a contradiction in ZFC or ZF?

Difference between class and struct in with regards to padding and inheritance

Applying for jobs with an obvious scar

Does unblocking power bar outlets through short extension cords increase fire risk?

Demographic consequences of closed loop reincarnation

How many opportunity attacks can you make per turn before becoming exhausted?



My add thousands comma function doesnt work


Is there an “exists” function for jQuery?How do JavaScript closures work?Add table row in jQueryvar functionName = function() vs function functionName() How does JavaScript .prototype work?Set a default parameter value for a JavaScript functionHow to print a number with commas as thousands separators in JavaScriptIs there a standard function to check for null, undefined, or blank variables in JavaScript?How can I add new array elements at the beginning of an array in Javascript?How does data binding work in AngularJS?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I have a function that converts a value to a value with a thousands comma, and it works with one of my other html forms, but not this one. Can anyone see a problem with my code?



---javascript---



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

function calcule2()
var i=0; for (i=0;i<= 29;i++) calcule();
function calcule(){

var C20 = Excel2Html.C20.value=+parseFloat(Excel2Html.C19.value)*parseFloat(Excel2Html.E16.value)*4;
var C21 = Excel2Html.C21.value=+parseFloat(Excel2Html.C20.value)*0.22;

Excel2Html.C20.value=(numberWithCommas(C20));
Excel2Html.C21.value=(numberWithCommas(C21));


---html---



<input type="text" onchange="calcule2()" name="E16" value="100" size="5" style="background: #67823A; border: none; color: #ffffff;">
<input type="text" onchange="calcule2()" name="C20" value="196000" size="5" disabled="disabled">
<input type="text" onchange="calcule2()" name="C21" value="43120" size="5" disabled="disabled">


C20 returns - 196000
C21 returns - 43120



However, it should be:



C20 = 196,000
C21 = 43,120










share|improve this question






















  • your numberWithCommas function seems to work just fine

    – Jaromanda X
    Mar 26 at 10:40

















0















I have a function that converts a value to a value with a thousands comma, and it works with one of my other html forms, but not this one. Can anyone see a problem with my code?



---javascript---



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

function calcule2()
var i=0; for (i=0;i<= 29;i++) calcule();
function calcule(){

var C20 = Excel2Html.C20.value=+parseFloat(Excel2Html.C19.value)*parseFloat(Excel2Html.E16.value)*4;
var C21 = Excel2Html.C21.value=+parseFloat(Excel2Html.C20.value)*0.22;

Excel2Html.C20.value=(numberWithCommas(C20));
Excel2Html.C21.value=(numberWithCommas(C21));


---html---



<input type="text" onchange="calcule2()" name="E16" value="100" size="5" style="background: #67823A; border: none; color: #ffffff;">
<input type="text" onchange="calcule2()" name="C20" value="196000" size="5" disabled="disabled">
<input type="text" onchange="calcule2()" name="C21" value="43120" size="5" disabled="disabled">


C20 returns - 196000
C21 returns - 43120



However, it should be:



C20 = 196,000
C21 = 43,120










share|improve this question






















  • your numberWithCommas function seems to work just fine

    – Jaromanda X
    Mar 26 at 10:40













0












0








0








I have a function that converts a value to a value with a thousands comma, and it works with one of my other html forms, but not this one. Can anyone see a problem with my code?



---javascript---



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

function calcule2()
var i=0; for (i=0;i<= 29;i++) calcule();
function calcule(){

var C20 = Excel2Html.C20.value=+parseFloat(Excel2Html.C19.value)*parseFloat(Excel2Html.E16.value)*4;
var C21 = Excel2Html.C21.value=+parseFloat(Excel2Html.C20.value)*0.22;

Excel2Html.C20.value=(numberWithCommas(C20));
Excel2Html.C21.value=(numberWithCommas(C21));


---html---



<input type="text" onchange="calcule2()" name="E16" value="100" size="5" style="background: #67823A; border: none; color: #ffffff;">
<input type="text" onchange="calcule2()" name="C20" value="196000" size="5" disabled="disabled">
<input type="text" onchange="calcule2()" name="C21" value="43120" size="5" disabled="disabled">


C20 returns - 196000
C21 returns - 43120



However, it should be:



C20 = 196,000
C21 = 43,120










share|improve this question














I have a function that converts a value to a value with a thousands comma, and it works with one of my other html forms, but not this one. Can anyone see a problem with my code?



---javascript---



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

function calcule2()
var i=0; for (i=0;i<= 29;i++) calcule();
function calcule(){

var C20 = Excel2Html.C20.value=+parseFloat(Excel2Html.C19.value)*parseFloat(Excel2Html.E16.value)*4;
var C21 = Excel2Html.C21.value=+parseFloat(Excel2Html.C20.value)*0.22;

Excel2Html.C20.value=(numberWithCommas(C20));
Excel2Html.C21.value=(numberWithCommas(C21));


---html---



<input type="text" onchange="calcule2()" name="E16" value="100" size="5" style="background: #67823A; border: none; color: #ffffff;">
<input type="text" onchange="calcule2()" name="C20" value="196000" size="5" disabled="disabled">
<input type="text" onchange="calcule2()" name="C21" value="43120" size="5" disabled="disabled">


C20 returns - 196000
C21 returns - 43120



However, it should be:



C20 = 196,000
C21 = 43,120







javascript






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 26 at 10:34









ABananaABanana

93 bronze badges




93 bronze badges












  • your numberWithCommas function seems to work just fine

    – Jaromanda X
    Mar 26 at 10:40

















  • your numberWithCommas function seems to work just fine

    – Jaromanda X
    Mar 26 at 10:40
















your numberWithCommas function seems to work just fine

– Jaromanda X
Mar 26 at 10:40





your numberWithCommas function seems to work just fine

– Jaromanda X
Mar 26 at 10:40












1 Answer
1






active

oldest

votes


















2














There are already methods for formatting numbers in the way you're looking for.



You can use toLocaleString()






function numberWithCommas(value) 
return Number(value).toLocaleString("en");


document.querySelector("#number").addEventListener("input", function()
console.log(numberWithCommas(this.value));
);

<input type="number" id="number" />








share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55354996%2fmy-add-thousands-comma-function-doesnt-work%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    There are already methods for formatting numbers in the way you're looking for.



    You can use toLocaleString()






    function numberWithCommas(value) 
    return Number(value).toLocaleString("en");


    document.querySelector("#number").addEventListener("input", function()
    console.log(numberWithCommas(this.value));
    );

    <input type="number" id="number" />








    share|improve this answer





























      2














      There are already methods for formatting numbers in the way you're looking for.



      You can use toLocaleString()






      function numberWithCommas(value) 
      return Number(value).toLocaleString("en");


      document.querySelector("#number").addEventListener("input", function()
      console.log(numberWithCommas(this.value));
      );

      <input type="number" id="number" />








      share|improve this answer



























        2












        2








        2







        There are already methods for formatting numbers in the way you're looking for.



        You can use toLocaleString()






        function numberWithCommas(value) 
        return Number(value).toLocaleString("en");


        document.querySelector("#number").addEventListener("input", function()
        console.log(numberWithCommas(this.value));
        );

        <input type="number" id="number" />








        share|improve this answer















        There are already methods for formatting numbers in the way you're looking for.



        You can use toLocaleString()






        function numberWithCommas(value) 
        return Number(value).toLocaleString("en");


        document.querySelector("#number").addEventListener("input", function()
        console.log(numberWithCommas(this.value));
        );

        <input type="number" id="number" />








        function numberWithCommas(value) 
        return Number(value).toLocaleString("en");


        document.querySelector("#number").addEventListener("input", function()
        console.log(numberWithCommas(this.value));
        );

        <input type="number" id="number" />





        function numberWithCommas(value) 
        return Number(value).toLocaleString("en");


        document.querySelector("#number").addEventListener("input", function()
        console.log(numberWithCommas(this.value));
        );

        <input type="number" id="number" />






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Mar 26 at 10:48

























        answered Mar 26 at 10:40









        ArcherArcher

        23.2k5 gold badges40 silver badges59 bronze badges




        23.2k5 gold badges40 silver badges59 bronze badges


















            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55354996%2fmy-add-thousands-comma-function-doesnt-work%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript