Skip to main content

Convert Chinese numerals and Arabic numerals.

Project description

cn2an = Chinese Numerals To Arabic Numerals.

本模块的作用是「中文数字」和「阿拉伯数字」互相转化。

安装

1 使用 pip 安装:

pip install cn2an

2 从代码库安装:

git clone https://github.com/kinggreenhall/cn2an.git
cd cn2an
python setup.py install

使用

1 在代码中直接调用:

import cn2an

# 1 中文数字转阿拉伯数字

cn2an.cn2an("一百万零五十四")
# output: 1000054

# 支持大写
cn2an.cn2an("壹佰万零伍十肆")
# output: 1000054

# 2 阿拉伯数字转中文数字

cn2an.an2cn("21024124")
cn2an.an2cn(21024124)
# output: 二千一百零二万四千一百二十四

# 支持小数
cn2an.an2cn("0.414")
cn2an.an2cn(0.414)
# output: 零点四一四

# 支持大写,需要增加额外的参数 True
cn2an.an2cn("21024124", True)
cn2an.an2cn(21024124, True)
# output: 贰仟壹佰零贰万肆仟壹佰贰拾肆
cn2an.an2cn("0.414", True)
cn2an.an2cn(0.414, True)
# output: 零点肆壹肆

2 通过命令行使用:

# 1 中文数字转阿拉伯数字

cn2an 一百万零五十四
# output: 1000054

# 支持小数
cn2an 零点四一四
# output: 0.414

# 支持大写
cn2an 壹佰万零伍十肆
# output: 1000054

# 2 阿拉伯数字转中文数字

an2cn 21024124
# output: 二千一百零二万四千一百二十四

# 支持小数
an2cn 0.414
# output: 零点四一四

# 支持大写,这里需要增加额外的参数 cap
cn2an cap 1000054
# output: 壹佰万零伍十肆
an2cn cap 0.414
# output: 零点肆壹肆

TODO

  • [x] 阿拉伯数字转大写中文数字。

  • [x] 关于零的bug。

  • [x] 支持 幺 == 1 的转化。

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cn2an-0.0.6.tar.gz (3.5 kB view details)

Uploaded Source

File details

Details for the file cn2an-0.0.6.tar.gz.

File metadata

  • Download URL: cn2an-0.0.6.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for cn2an-0.0.6.tar.gz
Algorithm Hash digest
SHA256 e3c4bd800995e9fe8676e2e84b51286e7b60db24299c07a69ebeaf64ae89de89
MD5 a926eadae4b81e9fb2f8211c00e84681
BLAKE2b-256 a3da57169a07fefa33f0f455008b7bc2f4036938eb016a7f79822106ac8703b8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page