美文网首页
人民币小写转换成大写

人民币小写转换成大写

作者: XH_hector | 来源:发表于2021-01-01 00:07 被阅读0次

之前Excel用过公式,Python试着写了下,写的有点累赘,不过应该可以用。
'''
aList = [u'零',u'壹',u'贰', u'叁',u'肆',u'伍',u'陆',u'柒',u'捌',u'玖',u'拾']

a1 = eval(input('请输入亿以下的数字: '))

if str(a1)[0] == '-':

a1 = -a1

print(u'负',end='' )

for i in range(len(str(a1))):

if str(a1)[i] == '.':

    a = int(a1)

    break 

else:

    a = a1

if a >= 10000:

a2 = a // 10000

if a2 >= 1000:

    print("{}仟".format(aList[int(str(a2)[-4])]),end='')

if int(str(a2)[-3:])  >= 100:

    print("{}佰".format(aList[int(str(a2)[-3])]),end='')

if a2 > 100 and  int(str(a2)[-3]) == 0 and int(str(a2)[-2]) != 0:

    print(u'零',end='') 

if int(str(a2)[-2:]) >= 10:

    print('{}拾'.format(aList[int(str(a2)[-2])]),end='')

if a2 > 10 and  int(str(a2)[-2]) == 0 and int(str(a2)[-1]) != 0:

    print(u'零',end='')

if a2 % 10 == 0:

    print(u'万',end='')

else:

    print('{}万'.format(aList[a2 % 10]),end='')

if a >10000 and int(str(a)[-5]) == 0 :

print(u'零',end='') 

if int(str(a)[-4:]) >= 1000:

print('{}仟'.format(aList[int(str(a)[-4])]),end='')

if a > 1000 and int(str(a)[-4]) == 0 and int(str(a)[-3]) != 0:

print(u'零',end='')   

if int(str(a)[-3:]) >= 100:

print('{}佰'.format(aList[int(str(a)[-3])]),end='')

if a >100 and int(str(a)[-3]) == 0 and int(str(a)[-2]) != 0:

print(u'零',end='')     

if int(str(a)[-2:]) >= 10:

print('{}拾'.format(aList[int(str(a)[-2])]),end='')

if a > 10 and int(str(a)[-2]) == 0 and int(str(a)[-1]) != 0:

print(u'零',end='')       

if a % 10 == 0:

if a != 0:

    print(u'圆',end='')

else:

    print((u'零圆'))

else:

print('{}圆'.format(aList[a % 10]),end='')

for i in range(len(str(a1))):

if str(a1)[i] == '.':

    x = int(str(a1).index('.'))+1

    if len(str(a1)[x:])>1:

        print("{}角{}分".format(aList[int(str(a1)[x])],aList[int(str(a1)[x+1])]))

    else:

        print("{}角".format(aList[int(str(a1)[x])]))

'''

相关文章

网友评论

      本文标题:人民币小写转换成大写

      本文链接:https://www.haomeiwen.com/subject/lfcdoktx.html