> ## Documentation Index
> Fetch the complete documentation index at: https://foliant-help.iforiti.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 模板中的金额和货币

> Foliant 的 Liquid 中，金额以分为单位。请使用货币过滤器打印金额，可使用订单的货币或其他货币。

在 Foliant 的 Liquid 中，每个金额都是以分为单位的整数：订单总额 100.00 即为 `10000`。这与 Shopify Order Printer 相同，因此您现有的模板会打印相同的金额。要打印金额，请始终使用货币过滤器：它会将数值除以 100 并加上货币。

## 货币过滤器

| 过滤器 | 示例 | 打印结果（商店格式 `${{amount}}`） |
| - | - | - |
| `money` | `{{ total_price \| money }}` | `$1,604.20` |
| `money_with_currency` | `{{ total_price \| money_with_currency }}` | `$1,604.20 USD` |
| `money_without_currency` | `{{ total_price \| money_without_currency }}` | `1,604.20` |
| `money_without_trailing_zeros` | `{{ 10000 \| money_without_trailing_zeros }}` | `$100` |
| `money_in` | `{{ amount \| money_in: 'EUR' }}` | 以您指定的货币显示的金额 |

* `money`、`money_with_currency`、`money_without_currency` 和 `money_without_trailing_zeros` 使用**订单的货币**，因此以加元支付的订单会以 CAD 打印。
* `money_in` 以订单货币以外的货币打印金额，例如以您本国货币显示增值税：`{{ vat_reporting.tax | money_in: vat_reporting.currency }}`。

## 金额以何种格式打印

模板的**数字格式**决定金额的显示方式，您可以在编辑器顶部栏或模板的设置页面中进行设置：

| 数字格式 | 作用 |
| - | - |
| **商店货币格式** | 使用您在 Shopify 后台设置的商店货币格式，与 Shopify Order Printer 相同。 |
| **文档语言的格式** | 按文档语言的习惯书写金额，例如德语中为 `1.234,56 €`。 |

`format_number` 始终使用文档语言的分隔符：在德语文档中，`{{ 1234.5 | format_number: 2 }}` 会打印 `1.234,50`。

## 以分为单位进行计算

由于金额以分为单位，请先进行计算，最后再设置格式：

```liquid theme={null}
{% assign balance = total_price | minus: total_paid %}
{% if balance > 0 %}
  {{ 'total_due' | t }}: {{ balance | money }}
{% endif %}
```

比较金额时也请使用分：`{% if total_price >= 10000 %}` 表示 100.00 或以上。

## 须知

* 货币过滤器会为每种货币打印正确的小数位数。有三位小数的货币（例如 KWD）会保留三位小数。
* 金额类型的元字段不以分为单位：它包含 `value`（例如 `23.00`）和 `unit`（货币代码）。请参阅[模板中的元字段](https://foliant-help.iforiti.com/cn/template-editor/metafields.md)。
* 订单项价格是扣除订单项折扣后的价格。整单折扣位于 `order_level_discounts` 中。请参阅[模板中的订单项](https://foliant-help.iforiti.com/cn/template-editor/liquid-line-items.md)。

## 相关文章

* [订单对象和常用变量](https://foliant-help.iforiti.com/cn/template-editor/liquid-order-variables.md)
* [Liquid 过滤器](https://foliant-help.iforiti.com/cn/template-editor/liquid-filters.md)
* [日期、语言和翻译](https://foliant-help.iforiti.com/cn/template-editor/liquid-dates-and-languages.md)
* [Liquid 中的条件内容](https://foliant-help.iforiti.com/cn/template-editor/liquid-conditional-content.md)


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