Skip to content

Commit

Permalink
fix: 修复中文数字转换函数对'十、十一'等数字的处理 (#275)
Browse files Browse the repository at this point in the history
  • Loading branch information
dludream authored Nov 27, 2024
1 parent 88fa431 commit 9a1b9d1
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions xiaomusic/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,13 @@ def chinese_to_number(chinese):
result = 0
unit = 1
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):
if char in chinese_to_arabic:
val = chinese_to_arabic[char]
Expand All @@ -536,8 +543,8 @@ def chinese_to_number(chinese):
unit *= val
else:
num += val * unit
result += num
num = 0
result += num

return result


Expand Down

0 comments on commit 9a1b9d1

Please sign in to comment.