dinero-formatting
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseDinero.js Formatting
Dinero.js 格式化
Patterns for formatting Dinero.js monetary values for display. Covers currency symbols, locale-aware formatting, non-decimal currencies, and serialization.
用于格式化Dinero.js货币值以供展示的模式,涵盖货币符号、地区感知格式化、非十进制货币和序列化相关内容。
When to Apply
适用场景
Reference these guidelines when:
- Displaying prices, totals, or monetary values in a UI
- Adding currency symbols or locale-specific formatting
- Formatting non-decimal currencies (e.g., historical currencies with non-base-10 subdivisions)
- Serializing Dinero objects for APIs, databases, or transport
- Building reusable formatting utilities
当出现以下情况时可参考这些指南:
- 在UI中展示价格、合计或其他货币值
- 添加货币符号或特定地区适配的格式
- 格式化非十进制货币(例如带有非10进制细分单位的历史货币)
- 序列化Dinero对象以供API、数据库或传输使用
- 构建可复用的格式化工具
Rule Categories by Priority
按优先级划分的规则类别
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | Display | CRITICAL | |
| 2 | Locale | HIGH | |
| 3 | Serialization | HIGH | |
| 4 | Non-Decimal | MEDIUM | |
| 优先级 | 类别 | 影响程度 | 前缀 |
|---|---|---|---|
| 1 | 展示 | 严重 | |
| 2 | 地区适配 | 高 | |
| 3 | 序列化 | 高 | |
| 4 | 非十进制 | 中 | |
Quick Reference
快速参考
1. Display (CRITICAL)
1. 展示(严重)
- - Use
display-to-decimalfor display strings, nottoDecimaltoSnapshot - - Dinero.js does not format currency symbols; compose with
display-no-currency-symbolsIntl.NumberFormat
- - 展示字符串使用
display-to-decimal,不要使用toDecimaltoSnapshot - - Dinero.js本身不处理货币符号格式化,请结合
display-no-currency-symbols使用Intl.NumberFormat
2. Locale (HIGH)
2. 地区适配(高)
- - Build reusable formatters with
locale-intl-formatterIntl.NumberFormat - - Create locale-parameterized formatters for multilingual sites
locale-multilingual
- - 使用
locale-intl-formatter构建可复用的格式化器Intl.NumberFormat - - 为多语言站点创建支持地区参数的格式化器
locale-multilingual
3. Serialization (HIGH)
3. 序列化(高)
- - Use
serialization-snapshotfor transport and storage, not displaytoSnapshot - - BigInt Dinero objects require a custom JSON replacer
serialization-bigint-json
- - 传输和存储使用
serialization-snapshot,不要用于展示toSnapshot - - BigInt类型的Dinero对象需要自定义JSON replacer
serialization-bigint-json
4. Non-Decimal (MEDIUM)
4. 非十进制(中)
- - Use
nondecimal-to-unitsfor non-decimal currencies, nottoUnitstoDecimal
- - 非十进制货币使用
nondecimal-to-units,不要使用toUnitstoDecimal
How to Use
使用方法
Read individual rule files for detailed explanations and code examples:
rules/display-no-currency-symbols.md
rules/locale-intl-formatter.mdEach rule file contains:
- Brief explanation of why it matters
- Incorrect code example with explanation
- Correct code example with explanation
- Additional context and references
阅读单个规则文件了解详细说明和代码示例:
rules/display-no-currency-symbols.md
rules/locale-intl-formatter.md每个规则文件包含:
- 规则重要性的简要说明
- 错误代码示例及解释
- 正确代码示例及解释
- 额外上下文和参考资料