Skip to main content

chinese-number-convertor

This is a simple Chinese number converter that converts between Chinese numbers and Arabic numbers.

👍 Quickstart

from cnc import convert

print(convert.chinese2number("五十七")) #57
print(convert.number2chinese(57)) #五十七

👉 chinese2number(string) -> (float|int)

Returns the arabic number representation of given string.

Notes

The function uses a loosely-matching logic, so the given string doesn't need to be confined to a specific pattern.

print(convert.chinese2number("兩千零一十二")) #2012
print(convert.chinese2number("二零一二")) #will also be 2012
print(convert.chinese2number("2012")) #will be, of course, 2012

That being said, please still avoid ambiguous and grammartically incorrect string such as 一兆一 or 一百一千億.

Support character

Support following characters:

  • Normal number: 一...九、十、百、千
  • Large number till 1052-1: 萬、億...極
  • Zero: 零、〇
  • Capital version of all characters above: 壹...玖、拾、佰、仟
  • Arabic number: 1...9、0
  • Simplified version off all characters above: 贰、万...

Arabic numbers were also supported because they will sometimes be mixed with characters, like "1億5000萬".

👉 number2chinese(int) -> (string)

Returns the chinese representation of given number.

Arguments

  • language: string, "T" or "S".
    • Choose between Traditional and Simplified characters.
    • (default is "T")
  • bigNumber: bool, True or False.
    • Output capital version of charaters.
    • (default is False)
print(convert.number2chinese(202)) #兩百零二
print(convert.number2chinese(202, language = "S", bigNumber = True)) #贰佰零贰
  • forceErLian: string, "auto", "force" or "forceNot".
    • Whether to distinguish Er(二) and Lian(兩).
      1. When set to "auto", the output will follow regional convention.
      2. When set to "force", both Traditional and Simplified version will distinguish word usage.
      3. When set to "forceNot", it will always output Er(二) for number "two".
    • (default is "auto")

This will only effect when not using capital number (bigNumber = False). Using capital number will always output 貳/贰.

print(convert.number2chinese(202, language = "T")) #兩百零二
print(convert.number2chinese(202, language = "T", forceErLian = "forceNot")) #二百零二
print(convert.number2chinese(202, language = "S")) #二百零二
print(convert.number2chinese(202, language = "S", forceErLian = "force")) #两百零二

Notes

This function uses "萬進" logic when dealing with larger number (>108), which basically means that every 4 digits will be treated as a group.

This is the most common logic to deal with large numbers, and can support up to 1052-1.

Metadata

Release files for ChineseNumberUtils 1.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ChineseNumberUtils 1.1.2
File Size Uploaded
ChineseNumberUtils-1.1.2.tar.gz 5.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ChineseNumberUtils 1.1.2
File Interpreter ABI Platform
ChineseNumberUtils-1.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 10.5 kB

Release files / ChineseNumberUtils-1.1.2.tar.gz

Download URL ChineseNumberUtils-1.1.2.tar.gz
Size 5.0 kB
Tags Source
SHA-256 checksum
How to use checksums
b84b2e02ee337c551ca3809e867982b30786f56211bd32b6218f6db7d27079e4
BLAKE2b-256 checksum
How to use checksums
b2d31ba75f350248ad2191d808e4065266189a9990b75a0b40286d2847e215bf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.7.9

Release files / ChineseNumberUtils-1.1.2-py3-none-any.whl

Download URL ChineseNumberUtils-1.1.2-py3-none-any.whl
Size 5.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
128f07e79038a7d6596cb99bbc60dbed64a976c75836116b5820fac341cb6cd7
BLAKE2b-256 checksum
How to use checksums
fa3742b82ab89d4e7025450cad95dcefcecc0095848ea1150e97c3ab075f34c8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.7.9

Release history Release notifications | RSS feed

This release

1.1.2 This release

2 release files

1.1.1

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page