JavaScript: Format Integers with Commas

Date: 2016-05-16 |

**Problem: **I have a set of large integers I’m trying to display on a page. As they are, they’re just a long string of numbers which makes it hard to tell where the thousands, millions, billions, etc. places are. How can I format these integers with commas so that they are human-readable?

**Solution: **The easiest solution is to use the built-in toLocaleString() function. It’s not the fastest method, but it’ll get the job done. I’ve tested it in FireFox and Chrome and it’s worked fine. For more info, you can check out the original StackOverflow post.

var num = 3000000;

console.log(num.toLocaleString()); //3,000,000

Want more like this?

The best / easiest way to support my work is by subscribing for future updates and sharing with your network.