普贤教程 › 包参考
money 包
金额格式化 / 解析
| 项 | 值 |
|---|---|
| 包名 | money |
| 版本 | 0.2.0 |
| 可用版本 | 0.1.0 / 0.2.0 |
| 入口 | money.px |
| 分类 | 数学与统计 |
| 文件数 / 行数 | 1 / 207 |
安装与引入
bash
pxpkg init # 首次 pxpkg add money@0.2.0 pxpkg install
px
import money所属分类教程:数学与统计
公开接口
| 函数 | 参数 |
|---|---|
mn_symbol | currency |
mn_decimals | currency |
mn_format | amount, currency = "CNY" |
mn_parse | s, currency = "CNY" |
其余 16 个 def(内部与辅助,可直接调用但不属稳定接口)
| 函数 | 参数 |
|---|---|
mn_digits | s |
mn_add | a, b, currency = "CNY" |
mn_sub | a, b, currency = "CNY" |
mn_mul | amount, quantity, currency = "CNY" |
mn_div | amount, quantity, currency = "CNY" |
mn_compare | a, b, currency = "CNY" |
mn_eq | a, b, currency = "CNY" |
mn_gt | a, b, currency = "CNY" |
mn_lt | a, b, currency = "CNY" |
mn_split | amount, n, currency = "CNY" |
mn_percent | amount, percentage, currency = "CNY" |
mn_discount | amount, discount_percent, currency = "CNY" |
mn_with_tax | amount, tax_percent, currency = "CNY" |
mn_convert | amount, rate |
mn_symbol_ext | currency |
mn_decimals_ext | currency |
包内说明(源码头注释)
text
============================================================ 普贤生态库:registry/money —— 金额格式化 / 解析 ------------------------------------------------------------ 纯函数库(无 IO、无状态),编译(px build)与解释(px run)双模式一致。 mn_format(amount, currency="CNY") → Ok(str) mn_parse(s, currency="CNY") → Ok(float) | Err mn_symbol(currency) / mn_decimals(currency) 货币:CNY ¥ / USD $ / EUR € / GBP £ / JPY ¥(0 位小数,其余 2 位)。 格式化用整数分(cents = round(amount*100))避免浮点尾数; 千分位为自实现字符串分组,不经 int 转换(任意长度安全)。 ============================================================