feat: human readable numbers for counts
This commit is contained in:
parent
64e052d317
commit
94cd7c72f6
3 changed files with 21 additions and 6 deletions
15
composables/numbers.ts
Normal file
15
composables/numbers.ts
Normal file
|
@ -0,0 +1,15 @@
|
|||
const formatter = Intl.NumberFormat()
|
||||
|
||||
export const humanReadableNumber = (num: number) => {
|
||||
if (num < 10000)
|
||||
return formatter.format(num)
|
||||
|
||||
if (num < 1000000)
|
||||
return `${Math.floor(num / 1000)}K`
|
||||
|
||||
return `${Math.floor(num / 1000000)}M`
|
||||
}
|
||||
|
||||
export const formattedNumber = (num: number) => {
|
||||
return formatter.format(num)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue