This commit is contained in:
2023-06-22 15:16:14 +01:00
parent 0ad5e387a1
commit 6a0ee5362a
16 changed files with 342 additions and 24 deletions

20
src/number.ts Normal file
View File

@ -0,0 +1,20 @@
const intlSats = new Intl.NumberFormat(undefined, {
minimumFractionDigits: 0,
maximumFractionDigits: 2,
});
export function formatShort(fmt: Intl.NumberFormat, n: number) {
if (n < 2e3) {
return n;
} else if (n < 1e6) {
return `${fmt.format(n / 1e3)}K`;
} else if (n < 1e9) {
return `${fmt.format(n / 1e6)}M`;
} else {
return `${fmt.format(n / 1e9)}G`;
}
}
export function formatSats(n: number) {
return formatShort(intlSats, n);
}