Skip to main content

A simple converter between Chinese and arabic number

Project description

chinese-number-convertor

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

👍 Quickstart

from chinese_number_converter.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: 零、〇
  • Captial 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.

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

ChineseNumberUtils-1.0.0.tar.gz (3.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ChineseNumberUtils-1.0.0-py3-none-any.whl (3.4 kB view details)

Uploaded Python 3

File details

Details for the file ChineseNumberUtils-1.0.0.tar.gz.

File metadata

  • Download URL: ChineseNumberUtils-1.0.0.tar.gz
  • Upload date:
  • Size: 3.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.7.9

File hashes

Hashes for ChineseNumberUtils-1.0.0.tar.gz
Algorithm Hash digest
SHA256 fdbc1c371904145adadd6f3833ce1430387d1522e8cb716ad8e32d2a02698a70
MD5 b0ee20b7ed6a86de9da5167dbd078a5e
BLAKE2b-256 5f22cbdd66c3bacbbef70a9771b6dbd37a778a0a6f5e412f14418c95dece655a

See more details on using hashes here.

File details

Details for the file ChineseNumberUtils-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for ChineseNumberUtils-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 adb26bec852ab02988e72889e1db3d2210707c13cecfaef21c81a2892b0659a3
MD5 2487b492ec830a876b587f9f1921e18c
BLAKE2b-256 643519138e1bd59f2377921562ee76b80551268d7dd5f9a9bbddfd5290f4a63f

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