# 将数字金额转换为对应的中文大写金额

• 阿拉伯数字转换为对应的中文大写，比如，对于阿拉伯数字1，对应输出

• 每个位置的数字后紧跟正确的单位，比如对于从右向左的第三位（不包含小数点），如果当前数字不为零，则需体现出的概念

• 连续的数字0不能输出多个，这是不符合日常习惯的

c_d = {'0': '零', '1': '壹', '2': '贰', '3': '叁', '4': '肆', '5': '伍', '6': '陆', '7': '柒', '8': '捌', '9': '玖'}

d_d = {0: '分', 1: '角', 2: '圆', 3: '拾', 4: '佰', 5: '仟', 6: '万', 7: '拾', 8: '佰', 9: '仟', 10: '亿', 11: '拾', 12: '佰',
13: '仟',
14: '万'}

def to_currency(number):
if not isinstance(number, float) and not isinstance(number, int):
return 'non number'
if number < 0 or number > 9999999999999.99:
return 'wrong number'
if number == 0:
return '零圆'
c_d = {'0': '零', '1': '壹', '2': '贰', '3': '叁', '4': '肆', '5': '伍', '6': '陆', '7': '柒', '8': '捌', '9': '玖'}
d_d = {0: '分', 1: '角', 2: '圆', 3: '拾', 4: '佰', 5: '仟', 6: '万', 7: '拾', 8: '佰', 9: '仟', 10: '亿', 11: '拾', 12: '佰',
13: '仟',
14: '万'}
L = []
pre = '0'
s = str(int(number * 100))[::-1].replace('.', '')
index = -1

for c in s:
index += 1
if c == '0' and pre == '0':
if index == 2:
L.insert(0, '圆')
elif c == '0':
if index == 2:
L.insert(0, '圆')
else:
L.insert(0, '零')
pre = c
else:
L.insert(0, c_d[c] + "" + d_d[index])
pre = c
return ''.join(L)


if __name__ == '__main__':
print(to_currency(123))
print(to_currency(14001))
print(to_currency(9999999999999))
print(to_currency(92830))
print(to_currency(92800))
print(to_currency(92800.89))
print(to_currency(92800.09))
print(to_currency(92800.98))
print(to_currency(92800.08))
print(to_currency(92800.90))
print(to_currency(900008.90))
print(to_currency(0.90))
print(to_currency(1.90))
print(to_currency(192.33))
print(to_currency(0))
print(to_currency(1))
print(to_currency(10))
print(to_currency(100))
print(to_currency(1000))

PS：测试案例只是部分，可能测试不充分，欢迎讨论！