Adding commas to a number in Javascript

I'm very new to Javascript and trying to add commas to a number.  I have the following code and I've spent hours trying to add commas to the FY2017bt value.  Any help would be greatly appreciated.

 
 var FY2017bt = 0; 
for(var i=0; i< FY2017BudgetTotal.value.length; i++){
  FY2017bt = FY2017bt + (FY2017BudgetTotal[i].value * 1.0);
}
FY2017BudgetTotalTotal[0].value = FY2017bt; 

Open in new window

ajdajdAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Julian HansenCommented:
Have you tried toLocaleString() ?
<script>
var x = 12233.34;
console.log(x.toLocaleString());
</script>

Open in new window

This will present the number in whatever locale is setup on the device.
2

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Martin MillerCTOCommented:
Let me add, comment by Julian is OK if the locale setup uses commas, e.g. for the numbers used in currency. But if not, then character counting, every 3rd from the decimal point will need a comma insertion.
0
ajdajdAuthor Commented:
I tried the following code and I get "console is not defined".  I am using this code inside a rule builder for a forms building application called Frevvo.  Maybe I need to define other things within the package?

var FY2017bt = 0; 

for(var i=0; i< FY2017BudgetTotal.value.length; i++){
  FY2017bt = FY2017bt + (FY2017BudgetTotal[i].value * 1.0);
}

FY2017BudgetTotalTotal[0].value = console.log(FY2017bt.toLocaleString());

Open in new window

0
Julian HansenCommented:
console.log was merely to output the value - it has no bearing on the solution.

Use whatever output mechanisms your environment supports.
0
Vijaya KumarCommented:
Are u looking for this?
<html charset="utf-8">
<script>
var a = [80,90,100];
var string='';
for(var i=0;i<a.length;i++)
	string = string + a[i]+',';
console.log(string);
</script>
<body>
<div id="output"></div>
<script>
document.getElementById("output").innerHTML = string;
</script>
</body>
</html>

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.