From 581b6e640174fabb741181646d656a24c3985745 Mon Sep 17 00:00:00 2001 From: encryptedDegen Date: Mon, 28 Oct 2024 19:52:24 +0100 Subject: [PATCH] build fixes --- src/utils/formatNumber.ts | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/src/utils/formatNumber.ts b/src/utils/formatNumber.ts index 1928ac99..878a3812 100644 --- a/src/utils/formatNumber.ts +++ b/src/utils/formatNumber.ts @@ -5,22 +5,14 @@ export const formatNumber = (number: number) => { } export const formatNumberLeaderboard = (number: number) => { - if (number >= 1e9) - return `${(number / 1e9).toLocaleString(navigator.language, { - maximumFractionDigits: 1, - roundingMode: 'floor' - })}B` - if (number >= 1e6) - return `${(number / 1e6).toLocaleString(navigator.language, { - maximumFractionDigits: 1, - roundingMode: 'floor' - })}M` - if (number >= 1e3) - return `${(number / 1e3).toLocaleString(navigator.language, { - maximumFractionDigits: 1, - roundingMode: 'floor' - })}k` + const formatter = new Intl.NumberFormat(navigator.language ?? 'en-US', { + maximumFractionDigits: 1, + }) + + const floorLastDigit = (num: number) => Math.floor(num * 10) / 10 + if (number >= 1e9) return `${formatter.format(floorLastDigit(number / 1e9))}B` + if (number >= 1e6) return `${formatter.format(floorLastDigit(number / 1e6))}M` + if (number >= 1e3) return `${formatter.format(floorLastDigit(number / 1e3))}k` return number.toString() } -