Formatting numbers with commas in javascript
In javascript you can use the Number.toLocaleString()
function to format the number correctly with commas. All you need is the BCP 47 language code to specify how to format the number (some countries/languages use periods instead of commas). It works like this:
number = 100000
number.toLocaleString('en-US');
// => "100,000"
Tweet