Today I Learned

hashrocket A Hashrocket project

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
// => "100,000"
See More #javascript TILs
Looking for help? At Hashrocket, our JavaScript experts launch scalable, performant apps on the Web, Android and iOS. Contact us and find out how we can help you.