Convert numbers in Chinese string to/from int
/float
/str
for Python3.8+.
pip install pycnnum
# git is required
git clone https://github.com/zcold/pycnnum.git
cd pycnnum
python -m pip install .
>>> from pycnnum import cn2num, num2cn
>>> cn2num("一 百 二 十 三 ")
123
>>> num2cn(123)
'一 百 二 十 三 '
>>> cn2num("一 兆 零 四 十 五 ", numbering_type="mid")
1000000000045
>>> num2cn(2400, alt_2=True)
'两千四 '
>>> num2cn(3.4)
'三 点 四 '
# example for working under Ubuntu 22.4
# git and python3.8-venv are required
git clone https://github.com/zcold/pycnnum.git pycnnum_dev
cd pycnnum_dev
python3.8 -m venv .venv
source .venv/bin/activate
python -m pip install .[dev] -U