2023-01-19 10:19:10 +00:00
|
|
|
const intl = new Intl.NumberFormat("en", {
|
|
|
|
minimumFractionDigits: 0,
|
|
|
|
maximumFractionDigits: 2,
|
|
|
|
});
|
|
|
|
|
2023-01-18 23:31:34 +00:00
|
|
|
export function formatShort(n: number) {
|
|
|
|
if (n < 999) {
|
|
|
|
return n
|
|
|
|
} else if (n < 1e8) {
|
2023-01-19 10:19:10 +00:00
|
|
|
return `${intl.format(Math.floor(n / 1e3))}K`
|
2023-01-18 23:31:34 +00:00
|
|
|
} else {
|
2023-01-19 10:19:10 +00:00
|
|
|
return `${intl.format(Math.floor(n / 1e6))}M`
|
2023-01-18 23:31:34 +00:00
|
|
|
}
|
|
|
|
}
|