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) {
|
2023-02-04 13:30:05 +00:00
|
|
|
if (n < 2e3) {
|
2023-02-07 20:04:50 +00:00
|
|
|
return n;
|
2023-02-07 13:32:32 +00:00
|
|
|
} else if (n < 1e6) {
|
2023-02-07 20:04:50 +00:00
|
|
|
return `${intl.format(n / 1e3)}K`;
|
2023-03-05 16:58:34 +00:00
|
|
|
} else if (n < 1e9) {
|
2023-02-07 20:04:50 +00:00
|
|
|
return `${intl.format(n / 1e6)}M`;
|
2023-03-05 16:58:34 +00:00
|
|
|
} else {
|
|
|
|
return `${intl.format(n / 1e9)}G`;
|
2023-01-18 23:31:34 +00:00
|
|
|
}
|
|
|
|
}
|