Zap flow
This commit is contained in:
20
src/number.ts
Normal file
20
src/number.ts
Normal 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);
|
||||
}
|
Reference in New Issue
Block a user