fix: 修复中文数字转换函数对'十、十一'等数字的处理 (#275)
This commit is contained in:
parent
88fa4318dc
commit
9a1b9d1949
@ -526,6 +526,13 @@ def chinese_to_number(chinese):
|
|||||||
result = 0
|
result = 0
|
||||||
unit = 1
|
unit = 1
|
||||||
num = 0
|
num = 0
|
||||||
|
# 处理特殊情况:以"十"开头时,在前面加"一"
|
||||||
|
if chinese.startswith('十'):
|
||||||
|
chinese = '一' + chinese
|
||||||
|
|
||||||
|
# 如果只有一个字符且是单位,直接返回其值
|
||||||
|
if len(chinese) == 1 and chinese_to_arabic[chinese] >= 10:
|
||||||
|
return chinese_to_arabic[chinese]
|
||||||
for char in reversed(chinese):
|
for char in reversed(chinese):
|
||||||
if char in chinese_to_arabic:
|
if char in chinese_to_arabic:
|
||||||
val = chinese_to_arabic[char]
|
val = chinese_to_arabic[char]
|
||||||
@ -537,7 +544,7 @@ def chinese_to_number(chinese):
|
|||||||
else:
|
else:
|
||||||
num += val * unit
|
num += val * unit
|
||||||
result += num
|
result += num
|
||||||
num = 0
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user