init: 项目初始提交 - NeoZQYY Monorepo 完整代码

This commit is contained in:
Neo
2026-02-15 14:58:14 +08:00
commit ded6dfb9d8
769 changed files with 182616 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
"""金额精度工具 — 人民币CNY统一使用 Decimal + ROUND_HALF_UP。
业务约定:所有金额字段保留 2 位小数(分),与数据库 numeric(*, 2) 对齐。
"""
from decimal import Decimal, ROUND_HALF_UP
CNY_SCALE = 2
_QUANT = Decimal("0." + "0" * CNY_SCALE)
def round_cny(amount: Decimal) -> Decimal:
"""人民币金额四舍五入到分。"""
return amount.quantize(_QUANT, rounding=ROUND_HALF_UP)
def to_cny(value) -> Decimal:
"""将任意数值转为 Decimal 并四舍五入到分。
接受 int / float / str / Decimal
不可解析时抛出 decimal.InvalidOperation。
"""
return round_cny(Decimal(str(value)))