> For the complete documentation index, see [llms.txt](https://docs.postgresql.tw/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.postgresql.tw/19/the-sql-language/datatype/datatype-money.md). Agents can also search and read this documentation through its [MCP server](https://docs.postgresql.tw/~gitbook/mcp).

# 8.2. 貨幣型別 \#

### 8.2. 貨幣型別 [#](#datatype-money) <a href="#datatype-money" id="datatype-money"></a>

`money` 型別以固定的小數精度儲存貨幣金額；請參閱[表 8.3](#datatype-money-table)。小數精度由資料庫的 [lc\_monetary](https://docs.postgresql.tw/19/server-administration/runtime-config/runtime-config-client.md#GUC-LC-MONETARY) 設定決定。表中所列的範圍假設有兩位小數。輸入時可接受多種格式，包括整數與浮點數常數，以及典型的貨幣格式，例如 `'$1,000.00'`。輸出通常採用後者的形式，但取決於語系。

#### 表 8.3. 貨幣型別 [#](#datatype-money-table) <a href="#datatype-money-table" id="datatype-money-table"></a>

| 名稱      | 儲存空間大小 | 說明   | 範圍                                            |
| ------- | ------ | ---- | --------------------------------------------- |
| `money` | 8 個位元組 | 貨幣金額 | -92233720368547758.08 至 +92233720368547758.07 |

<br>

由於這個資料型別的輸出會受語系影響，將 `money` 資料載入到 `lc_monetary` 設定不同的資料庫中可能無法正常運作。為避免問題，在把備份傾印還原到新資料庫之前，請確認 `lc_monetary` 與被傾印的資料庫具有相同或等效的值。

`numeric`、`int` 與 `bigint` 資料型別的值可以轉換為 `money`。從 `real` 與 `double precision` 資料型別轉換時，可以先轉換為 `numeric` 來完成，例如：

```

SELECT '12.34'::float8::numeric::money;
```

不過並不建議這麼做。由於可能產生捨入誤差，浮點數不應該用來處理金錢。

`money` 值可以在不損失精度的情況下轉換為 `numeric`。轉換為其他型別則可能會損失精度，而且同樣必須分兩個階段進行：

```

SELECT '52093.89'::money::numeric::float8;
```

`money` 值除以整數值時，小數部分會朝零的方向被截斷。若要取得四捨五入的結果，請除以浮點數值，或是在相除之前先將 `money` 值轉換為 `numeric`，之後再轉換回 `money`。（為了避免損失精度的風險，後者較為可取。）當 `money` 值除以另一個 `money` 值時，結果會是 `double precision`（也就是純粹的數字，而非金額）；相除時貨幣單位會互相抵消。

***

原文：[PostgreSQL 18.6 Documentation](https://www.postgresql.org/docs/18/datatype-money.html)（原文版本：18.6；核對日期：2026-09-13）


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.postgresql.tw/19/the-sql-language/datatype/datatype-money.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
