Skip to content

Components

Token Amount

Formats bigint token amounts without losing precision.

Formats a raw bigint amount for display. Precision is never lost to floating point, and amounts always round toward zero, so a balance never looks larger than it is. Hover to see the exact amount.

1,234.5678USDC
Terminal window
npx shadcn@latest add @0xui/token-amount
import { TokenAmount } from "@/components/token-amount";
<TokenAmount value={balance} decimals={6} symbol="USDC" />;

0xui doesn’t fetch prices. Pass your own.

2.5ETH$7,876.05
<TokenAmount value={balance} decimals={18} symbol="ETH" price={ethPrice} />
12.5MARB
<TokenAmount value={supply} decimals={18} symbol="ARB" compact />

Non-zero amounts too small to show render as a bound instead of a misleading 0.

<0.0001ETH
Prop Type Default Description
value bigint — Amount in the token’s smallest unit.
decimals number — Token decimals.
symbol string — Shown after the amount.
maxDecimals number 4 Maximum fraction digits.
compact boolean false Compact notation, e.g. 1.2M.
price number — Price of one token. Adds a fiat line.
currency string "USD" ISO 4217 currency for the fiat value.
locale string runtime locale Number formatting locale.
animate boolean false Morph the amount and fiat value when they change, with Morph Text. Leave off in long lists.