Skip to content

Commit

Permalink
fix leaderboard rounding function
Browse files Browse the repository at this point in the history
  • Loading branch information
encryptedDegen committed Oct 28, 2024
1 parent 74af441 commit 7a5e04b
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/utils/formatNumber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,23 @@ export const formatNumber = (number: number) => {
return formattedNumber
}

export const formatNumberLeaderboard = (num: number) => {
const number = Math.floor(num * 10) / 10
export const formatNumberLeaderboard = (number: number) => {
if (number >= 1e9)
return `${(number / 1e9).toLocaleString(navigator.language, {
maximumFractionDigits: 1
maximumFractionDigits: 1,
roundingMode: 'floor'
})}B`
if (number >= 1e6)
return `${(number / 1e6).toLocaleString(navigator.language, {
maximumFractionDigits: 1
maximumFractionDigits: 1,
roundingMode: 'floor'
})}M`
if (number >= 1e3)
return `${(number / 1e3).toLocaleString(navigator.language, {
maximumFractionDigits: 1
maximumFractionDigits: 1,
roundingMode: 'floor'
})}k`
return num.toString()

return number.toString()
}

0 comments on commit 7a5e04b

Please sign in to comment.