> For the complete documentation index, see [llms.txt](https://docs.opinion.trade/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.opinion.trade/developer-guide/opinion-clob-typescript-sdk/core-concepts/precision.md).

# Precision

Understanding token decimals, price formats, and amount conversions is critical for correct trading.

## Token Decimal System

Both USDT (collateral) and outcome tokens (YES/NO) use **18 decimal places**:

| Human Amount | Wei Amount                        |
| ------------ | --------------------------------- |
| 1 USDT       | 1,000,000,000,000,000,000 (10^18) |
| 0.5 USDT     | 500,000,000,000,000,000           |
| 100 USDT     | 100,000,000,000,000,000,000       |

## Price Format

Prices are strings representing implied probability:

* Valid range: `0.01` to `0.99`
* Maximum 4 decimal places
* `"0.50"` = 50% probability = $0.50 per token = $1.00 payout if correct

## Wei Conversion

The SDK provides a `safeAmountToWei` utility for converting human-readable amounts to wei:

{% code title="example.ts" %}

```typescript
import { safeAmountToWei } from '@opinion-labs/opinion-clob-sdk';

// Convert human amount to wei
const weiAmount = safeAmountToWei(100.0, 18); // 100 USDT -> wei
console.log(weiAmount); // 100000000000000000000n (BigInt)

// For smart contract operations, pass BigInt directly
await client.split(123, weiAmount);
```

{% endcode %}

{% hint style="warning" %}
Use BigInt for wei amounts to avoid JavaScript number precision issues.
{% endhint %}

Example comparisons:

{% code title="bigint-examples.ts" %}

```typescript
// Correct - BigInt
const amount = BigInt(100) * BigInt(10 ** 18);

// Avoid - Number (loses precision for large values)
const amount = 100 * 10 ** 18; // May lose precision!
```

{% endcode %}

You can also construct wei values directly with `BigInt`:

{% code title="direct-wei.ts" %}

```typescript
// 100 USDT in wei
const oneHundredUsdt = BigInt(100) * BigInt(10 ** 18);

// 0.5 USDT in wei
const halfUsdt = BigInt(5) * BigInt(10 ** 17);
```

{% endcode %}

## Order Amount Handling

When placing orders, provide amounts in **human-readable format** (not wei). The SDK handles conversion internally.

{% code title="place-order.ts" %}

```typescript
import { OrderSide, OrderType, type PlaceOrderDataInput } from '@opinion-labs/opinion-clob-sdk';

// Spend 10 USDT - provide as string, SDK converts to wei internally
const order: PlaceOrderDataInput = {
  marketId: 123,
  tokenId: 'token_id',
  side: OrderSide.BUY,
  orderType: OrderType.LIMIT_ORDER,
  price: '0.5',
  makerAmountInQuoteToken: '10', // 10 USDT (human-readable)
};
```

{% endcode %}

The distinction is important:

* **Order amounts** (`makerAmountInQuoteToken`, `makerAmountInBaseToken`): human-readable strings, SDK converts internally
* **Smart contract amounts** (`split`, `merge`): wei as `bigint`, you must convert manually

## Common Errors to Avoid

{% stepper %}
{% step %}
Wrong decimals

USDT uses 18 decimals (not 6) in this system.
{% endstep %}

{% step %}
Float arithmetic

Use `BigInt` for precise wei calculations.
{% endstep %}

{% step %}
Price range

Prices must be within `[0.01, 0.99]`.
{% endstep %}

{% step %}
Manual wei conversion for orders

The SDK handles this; provide human-readable amounts.
{% endstep %}

{% step %}
Manual wei conversion for split/merge

You must provide wei amounts directly.
{% endstep %}
{% endstepper %}
