Appearance
formatCompactTokenAmount
Abbreviates large token magnitudes with uppercase K / M suffixes. Returns '' below the threshold so callers can fall back to a full format.
ts
import { formatCompactTokenAmount } from '@swapped/connect-sdk/format'Default threshold (10000)
ts
formatCompactTokenAmount(9999)
// "" — below threshold → caller should fall back
formatCompactTokenAmount(10000)
// "10K"
formatCompactTokenAmount(12500)
// "12.50K"
formatCompactTokenAmount(125000)
// "125K"
formatCompactTokenAmount(1_500_000)
// "1.50M"
formatCompactTokenAmount(2_000_000)
// "2M"Custom threshold
ts
formatCompactTokenAmount(5000, 1000)
// "5K" — second arg lowers the minimum| Param | Default | Purpose |
|---|---|---|
num | — | Numeric amount |
minThreshold | 10000 | Minimum value that triggers compact format |
formatTokenAmount uses this when useLargeNumberFormat is enabled.