refactor: improve community count formatting

This commit is contained in:
hajimi
2026-08-02 20:32:57 +08:00
parent a1ed73b0ec
commit 31ffedbcf2
@@ -174,9 +174,18 @@ const formatTime = (value: any) => {
} }
const formatCount = (value: any) => { const formatCount = (value: any) => {
const count = Number(value || 0) const numericValue = Number(value)
if (count >= 10000) return `${(count / 10000).toFixed(1)}` if (!Number.isFinite(numericValue) || numericValue <= 0) return '0'
if (count >= 1000) return `${(count / 1000).toFixed(1)}k`
const count = Math.floor(numericValue)
const compact = (divisor: number, unit: string) => {
const formatted = (count / divisor).toFixed(1).replace(/\.0$/, '')
return `${formatted}${unit}`
}
if (count >= 100000000) return compact(100000000, '亿')
if (count >= 10000) return compact(10000, '万')
if (count >= 1000) return compact(1000, 'k')
return String(count) return String(count)
} }
</script> </script>