Problem
You want to transform thousand numbers into their compact version (1,000 -> 1k).
Solution
Use Intl.NumberFormat
with the compact
notation as option
const formatter = new Intl.NumberFormat("en-US", { notation: "compact" });
const number = 12_000;
const formattedNumber = formatter.format(number) // -> will return '12k'
Top comments (0)