Intl API: Number Formatting
Format numbers like 5.2K or 1.7M using the JavaScript Internationalization APIThe _ 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.7MCurrency
const currencyFormatter = Intl.NumberFormat("en", { notation: "compact", style: "currency", currency: "USD",});
const amount = currencyFormatter.format(5_210);console.log(amount); // $5.2K