# Token Amount

> Formats bigint token amounts without losing precision.

- Install: `npx shadcn@latest add @0xui/token-amount`
- Registry JSON: https://0xui.io/r/token-amount.json
- Source: https://github.com/fimbul-lab/0xui/blob/main/registry/default/components/token-amount.tsx

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.

## Installation

```bash
npx shadcn@latest add @0xui/token-amount
```

## Usage

```tsx
import { TokenAmount } from "@/components/token-amount";

<TokenAmount value={balance} decimals={6} symbol="USDC" />;
```

## Examples

### With fiat value

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

```tsx
<TokenAmount value={balance} decimals={18} symbol="ETH" price={ethPrice} />
```

### Compact

```tsx
<TokenAmount value={supply} decimals={18} symbol="ARB" compact />
```

### Dust

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

## Props

| 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](https://0xui.io/components/morph-text.md). Leave off in long lists. |
