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;
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
add a comment |
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
yournumberWithCommas
function seems to work just fine
– Jaromanda X
Mar 26 at 10:40
add a comment |
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
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
javascript
asked Mar 26 at 10:34
ABananaABanana
93 bronze badges
93 bronze badges
yournumberWithCommas
function seems to work just fine
– Jaromanda X
Mar 26 at 10:40
add a comment |
yournumberWithCommas
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
add a comment |
1 Answer
1
active
oldest
votes
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" />
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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" />
add a comment |
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" />
add a comment |
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" />
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" />
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
add a comment |
add a comment |
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.
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
your
numberWithCommas
function seems to work just fine– Jaromanda X
Mar 26 at 10:40