diff options
| author | Adam Soltys <[email protected]> | 2024-11-09 11:28:04 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2024-11-09 11:28:04 -0800 |
| commit | 542c24b17643bc1a743c6d5eca3e3a29947c72b5 (patch) | |
| tree | 300ecabce7e1b85c1aad64780e8404c3542dfad7 /src/lib/utils.ts | |
| parent | d47895ec4d54feef1114029ba11188362fa1222d (diff) | |
| download | coinos-ui-542c24b17643bc1a743c6d5eca3e3a29947c72b5.tar.gz coinos-ui-542c24b17643bc1a743c6d5eca3e3a29947c72b5.zip | |
fix 2fa
Diffstat (limited to 'src/lib/utils.ts')
| -rw-r--r-- | src/lib/utils.ts | 20 |
1 files changed, 11 insertions, 9 deletions
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] ); }; |
