阿拉伯数字转化为中文的数字(金额)
生活随笔
收集整理的這篇文章主要介紹了
阿拉伯数字转化为中文的数字(金额)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
def numToBig(num):dict1 = {1:'壹',2:'貳',3:'叁',4:'肆',5:'伍',6:'陸',7:'柒',8:'捌',9:'玖',0:'零'}dict2 = {2:'拾',3:'佰',4:'仟',5:'萬',6:'拾',7:'佰',8:'仟',1:'元',9:'角',10:'分',11:'整'}money = '' #最終大寫數字flag = False #去掉多余的十百千flag2 = False #增加零ifint = False #整count = 0count2 = 8#num = 11324strnum = str(num)aa = strnum.split('.')bb = list(str(aa[:1])[2:-2])cc = list(str(aa[1:])[2:-2])#此處控制:無小數時輸出xxx元整#若要求一位小數也帶整,即xxx元整并且xxx元xx角整,則修改下方0為1if len(cc) <= 0:ifint = Trueelse:ifint = False#整數部分for i in reversed(bb):count = count + 1if(int(i) == 0):if(flag == True):if(count != 5):continueelse:money = dict2[count] + moneyelse:if(flag2 == False):money = dict2[count] + moneyelse:if(count != 5):money = '零' + moneyelse:money = dict2[count] + '零' +moneyflag = Trueelse:flag = Falseflag2 = Truemoney = dict1[int(i)]+dict2[count]+money#小數部分for i in cc:count2 = count2 + 1money = money + dict1[int(i)] + dict2[count2]if(ifint == True):money = money + '整'return money
總結
以上是生活随笔為你收集整理的阿拉伯数字转化为中文的数字(金额)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 最新中国移动光猫改桥接方式(中兴ZXHN
- 下一篇: 带你一步步破解Android微信聊天记录