From 542c24b17643bc1a743c6d5eca3e3a29947c72b5 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Sat, 9 Nov 2024 11:28:04 -0800 Subject: fix 2fa --- src/lib/utils.ts | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'src/lib/utils.ts') diff --git a/src/lib/utils.ts b/src/lib/utils.ts index b27ce5f1..2779e34a 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -216,19 +216,21 @@ export const f = (s: number, currency: string): string => { export const s = (s: number): string => new Intl.NumberFormat("en-US", { maximumFractionDigits: 0 }).format(s); -export const sat = (s: number): string => `⚡️${si(Math.abs(s)).toString()}`; - -export const si = (s: number) => { - if (s < 1000) return s.toString(); // Return the original number if it's less than 1000 +export const sat = (s: number): string => `${si(Math.abs(s)).toString()}`; +export const si = (n: number, minimumFractionDigits = 1, maximumFractionDigits = 2) => { const units = ["", "K", "M", "G", "T", "P", "E", "Z"]; - const d = Math.floor(Math.log10(s) / 3); // Calculate the unit index - const scaled = s / 1000 ** d; // Scale the number to the correct unit + + let s = n; + let d = 0; + if (s >= 1000) { + d = Math.floor(Math.log10(s) / 3); // Calculate the unit index + s = n / 1000 ** d; // Scale the number to the correct unit + } return ( - new Intl.NumberFormat("en-US", { maximumFractionDigits: 2 }).format( - scaled, - ) + units[d] + new Intl.NumberFormat("en-US", { minimumFractionDigits, maximumFractionDigits }).format(s) + + units[d] ); }; -- cgit v1.2.3