Chinese/Arabic Numeral Converter (cn2an)

0.5.23 · active · verified Thu Apr 16

cn2an is a Python toolkit for quickly converting between Chinese numerals and Arabic numerals. It supports conversion of standard Chinese numbers, large-form Chinese numbers, mixed Chinese and Arabic numbers, and provides features for sentence-level conversion, including dates, fractions, percentages, and temperatures. The library is actively maintained, with the latest version being 0.5.23, and targets Python 3.6+ for local installation.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates basic conversion from Chinese to Arabic and Arabic to Chinese numerals, along with sentence-level transformation. Various modes (`strict`, `normal`, `smart` for cn2an; `low`, `up`, `rmb` for an2cn) are available to handle different input formats.

import cn2an

# Chinese to Arabic conversion (strict mode is default)
arabic_num = cn2an.cn2an("一百二十三")
print(f"'一百二十三' -> {arabic_num}")

# Arabic to Chinese conversion (low mode is default)
chinese_num = cn2an.an2cn("12345")
print(f"'12345' -> {chinese_num}")

# Sentence transformation (experimental)
sentence = cn2an.transform("小王捡了一百块钱")
print(f"'小王捡了一百块钱' -> {sentence}")

view raw JSON →