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.
pip install cn2an -UVerified import paths — ran on the pinned version, not inferred.
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.
Ensure your environment uses Python 3.6 or newer. Upgrade your Python interpreter if necessary.
For critical applications, carefully test `transform()` with your specific sentence patterns. Consider using `cn2an.cn2an()` or `cn2an.an2cn()` on extracted number phrases for more predictable results.
Consult the documentation for available modes and their specific behaviors. Explicitly pass the desired `mode` argument to the conversion functions (e.g., `cn2an.cn2an('一二三', 'normal')`) to ensure correct parsing.