Appearance
formatCurrencyAmount
Primary helper for USD-style amounts (mins, maxes, wallet value). Wraps formatCurrency with smarter defaults for small values and trailing zeros.
ts
import { formatCurrencyAmount } from '@swapped/connect-sdk/format'Defaults (2 decimals, pretty)
ts
formatCurrencyAmount(0)
// "0.00"
formatCurrencyAmount(12)
// "12.00"
formatCurrencyAmount(12.3)
// "12.30"
formatCurrencyAmount(12.345)
// "12.35"
formatCurrencyAmount(1234.5)
// "1,234.50"format: 'js-number'
ts
formatCurrencyAmount(1234.5, { format: 'js-number' })
// "1234.50" — no thousand separators (good for inputs)Tiny amounts (firstNonZeroDecimal)
Without the flag, values under 0.01 collapse to "0.00". With it, precision expands until the first significant digit is visible.
ts
formatCurrencyAmount(0.004)
// "0.00"
formatCurrencyAmount(0.004, { firstNonZeroDecimal: true })
// "0.004"
formatCurrencyAmount(0.00004)
// "0.00"
formatCurrencyAmount(0.00004, { firstNonZeroDecimal: true })
// "0.00004"
formatCurrencyAmount(0.0001, { firstNonZeroDecimal: true })
// "0.0001"Trailing zeros (removeTrailingZeros)
ts
formatCurrencyAmount('1.50')
// "1.50"
formatCurrencyAmount('1.50', { removeTrailingZeros: true })
// "1.5"
formatCurrencyAmount('1.5000', { removeTrailingZeros: true })
// "1.5"
formatCurrencyAmount(1000.1, { removeTrailingZeros: true })
// "1,000.1"| Option | Default | Purpose |
|---|---|---|
format | 'pretty' | 'pretty' adds thousand separators; 'js-number' does not |
firstNonZeroDecimal | false | Expand past 2 decimals so tiny values are visible |
removeTrailingZeros | false | Strip trailing zeros after the decimal |
Prefer this over formatCurrency unless you need an explicit decimals count.