Formatting numbers

638
3
Jump to solution
04-19-2012 02:14 PM
RachelLinonis
New Contributor
Hopefully this is another easy question for you all ...

I have a number variable, and I want it to be formatted with commas (like 3,000 instead of 3000). My API lets the user select a bunch of polygons and it calculates a population total in the background. The number comes back correct, I just can't seem to figure out how to format it ....

           function sumVeterans(features) {                 var imputedSum = 0;                 //summarize the cummulative gas production to display                 dojo.forEach(features, function(feature) {                     imputedSum = imputedSum + feature.attributes.ImputedVeteran;                 });                 //dojo.byId('messages').innerHTML = "Total Veterans: " + imputedSum + "";                 var formattedImputedSum = imputedSum                 dojo.byId('messages').innerHTML = "Total Veterans: " + imputedSum + "";             }
0 Kudos
1 Solution

Accepted Solutions
derekswingley1
Frequent Contributor
Use dojo.number.format:

var formatted = dojo.number.format(3000); // returns "3,000"

View solution in original post

0 Kudos
3 Replies
derekswingley1
Frequent Contributor
Use dojo.number.format:

var formatted = dojo.number.format(3000); // returns "3,000"
0 Kudos
RachelLinonis
New Contributor
Thank you!
0 Kudos
derekswingley1
Frequent Contributor
You're welcome!
0 Kudos