Intl API: Number Formatting

The _ between numbers are numeric separators, although they are unnecessary, I find large numbers more readable this way.

Table of contents

Views Counter

const viewsFormatter = Intl.NumberFormat("en", {
	notation: "compact",
});

const views = viewsFormatter.format(1_722_012_999);
console.log(views); // 1.7M

Currency

const currencyFormatter = Intl.NumberFormat("en", {
	notation: "compact",
	style: "currency",
	currency: "USD",
});

const amount = currencyFormatter.format(5_210);
console.log(amount); //  $5.2K

Updates

Subscribe to my personal newsletter.

Join others! 100% Free. No spam. Privacy Policy

Related snippets