This is a simple Chinese number converter that converts between Chinese numbers and Arabic numbers.
from cnc import convert
print(convert.chinese2number("五十七")) #57
print(convert.number2chinese(57)) #五十七Returns the arabic number representation of given string.
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, 2012That being said, please still avoid ambiguous and grammartically incorrect string such as
一兆一or一百一千億.
Support following characters:
Arabic numbers were also supported because they will sometimes be mixed with characters, like "1億5000萬".
Returns the chinese representation of given number.
print(convert.number2chinese(202)) #兩百零二
print(convert.number2chinese(202, language = "S", bigNumber = True)) #贰佰零贰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")) #两百零二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.