feat(i18n): use compact number format instead K/M suffix (#678)

This commit is contained in:
Joaquín Sánchez 2023-01-01 20:31:14 +01:00 committed by GitHub
parent d0567c0d18
commit ca93f1a813
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 14 additions and 30 deletions

View file

@ -8,18 +8,18 @@ export const formattedNumber = (num: number, useFormatter: Intl.NumberFormat = f
}
export const useHumanReadableNumber = () => {
const { t, n, locale } = useI18n()
const { n, locale } = useI18n()
const fn = (num: number) => {
if (num < 10000)
return n(num, 'smallCounting', locale.value)
// show 1 decimal: we cannot use toFixed(1), it is a string
if (num < 1000000)
return `${n(Math.floor(num / 100) / 10, 'kiloCounting', locale.value)}${t('common.kiloSuffix')}`
// show 2 decimals: we cannot use toFixed(2), it is a string
return `${n(Math.floor(num / 10000) / 100, 'millionCounting', locale.value)}${t('common.megaSuffix')}`
return n(
num,
num < 10000
? 'smallCounting'
: num < 1000000
? 'kiloCounting'
: 'millionCounting',
locale.value,
)
}
return {