loading...

Formatting large numbers in JavaScript

gautemeekolsen profile image Gaute Meek Olsen ・1 min read

How to get a formatted number easily in JavaScript that is human-readable with Intl.NumberFormat.

Let's say we want to display three million, 3000000. This isn't that easy to read, you need to look closely to check that it isn't 300,000 or 30,000,000.

const number = 3000000;
const numberToDisplay = new Intl.NumberFormat().format(number)

Bonus, it will be formatted according to the users' local settings. For me in Norway, numberToDisplay is 3 000 000. While 'en-US' it will be 3,000,000 and 'de-DE' it is 3.000.000

Discussion

markdown guide