> ## Documentation Index
> Fetch the complete documentation index at: https://docs.arksat.xyz/llms.txt
> Use this file to discover all available pages before exploring further.

# 金额与小数精度

> 精确处理资产数量和小数。

| 数据 | 类型与单位 |
| - | - |
| BTC 余额、发送数量、历史 amount | `number`，整数 sats |
| 资产数量、供应量 | `string`，整数最小单位 |
| 用户输入小数 | 保持字符串，精确转换后提交 |
| 精确展示 | `displayAmountText` 或 `formatRawAssetAmount` |

```ts theme={null}
import { decimalAmountToRaw, formatRawAssetAmount } from '@arksat/wallet-sdk'

export const raw = decimalAmountToRaw('1.25', 8) // '125000000'
export const text = formatRawAssetAmount('1000000000000000001', 18)
// '1.000000000000000001'
```

不要先 `Number(input)`，不要用浮点乘法 `input * 10 ** decimals`，不要从近似 `displayAmount` 反推交易数量。

`decimalAmountToRaw` 支持 0–18 位小数，拒绝超出精度的小数和超过 uint64 的数量，不截断、不四舍五入。上限为 `18446744073709551615` 个最小单位。转换允许零，发送、发行、增发、销毁必须大于零。

`toRawAmountString` 用于校验和规范化原始整数数量，不能代替小数转换，具体输入约束见类型声明。

`metadataPending` 为真或 decimals 未确定时，显示标明单位的原始数量，等待可信元数据后再接受小数输入，不要默认 8 位。大整数进入 JSON 前保持字符串。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.