woocommerce/packages/js/currency/zh-cn/README.md
2026-04-15 10:18:01 +08:00

33 lines
No EOL
1.4 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 货币
一组用于显示和处理货币价值的实用工具。
## 安装
安装模块
```bash
pnpm install @woocommerce/currency --save
```
_本包假定您的代码将在 **ES2015+** 环境中运行。如果您使用的环境对 ES2015+ 支持有限或不支持(例如较低版本的 IE那么使用 [core-js](https://github.com/zloirock/core-js) 或 [@babel/polyfill](https://babeljs.io/docs/en/next/babel-polyfill) 将为这些方法添加支持。在 [Babel 文档](https://babeljs.io/docs/en/next/caveats) 中了解更多信息。_
## 用法
```JS
import CurrencyFactory from '@woocommerce/currency';
const storeCurrency = CurrencyFactory(); // 将商店设置传入构造函数。
// 使用给定的货币符号格式化金额。使用站点的货币设置进行格式化,
// 这些设置来自设置 API。默认为 symbol=`$`, precision=2, decimalSeparator=`.`, thousandSeparator=`,`
const total = storeCurrency.formatAmount( 20.923 ); // '$20.92'
// 获取一个数值在当前货币精度下的四舍五入十进制值,
// 精度来自设置 API。默认为 2。
const total = storeCurrency.formatDecimal( '6.2892' ); // 6.29
// 获取一个浮点数的字符串表示,精度与当前货币使用的精度一致。
// 这与 `formatAmount` 的不同之处在于不返回货币符号。
const total = storeCurrency.formatDecimalString( 1088.478 ); // '1088.48'
```