px普贤教程PuXian
普贤教程 › 包参考

num2words 包

英文数字转单词

项值
包名num2words
版本0.2.0
可用版本0.1.0 / 0.2.0
入口num2words.px
分类文本与中文处理
文件数 / 行数1 / 160

安装与引入

bash
pxpkg init          # 首次
pxpkg add num2words@0.2.0
pxpkg install
px
import num2words
所属分类教程:文本与中文处理

公开接口

函数参数
nw_convertn
其余 8 个 def(内部与辅助,可直接调用但不属稳定接口)
函数参数
nw_onest
nw_tenst
nw_twon
nw_threen
nw_absn
nw_to_words_enn
nw_to_words_cnn
nw_currencyn, currency="CNY"

包内说明(源码头注释)

text
============================================================
普贤生态库:registry/num2words —— 英文数字转单词
------------------------------------------------------------
纯函数库(无 IO、无状态),编译(px build)与解释(px run)双模式一致。
nw_convert(n) → Ok(str) | Err  整数(±999,999,999,999)→ 英文单词
规则:
- 0 → "zero";负 → "minus X"
- 21-99 连字符(forty-two);百位后接 "and"(one hundred and five)
- 千/百万/十亿分组(one thousand / one million / one billion)
============================================================