snort/src/Number.ts
ennmichael 5ad4971fc0
Add prettier formatting (#214)
* chore: add prettier

* chore: format codebase
2023-02-07 20:04:50 +00:00

15 lines
295 B
TypeScript

const intl = new Intl.NumberFormat("en", {
minimumFractionDigits: 0,
maximumFractionDigits: 2,
});
export function formatShort(n: number) {
if (n < 2e3) {
return n;
} else if (n < 1e6) {
return `${intl.format(n / 1e3)}K`;
} else {
return `${intl.format(n / 1e6)}M`;
}
}