defconvert(num):"""
数字转化成大写
:param num: [int/string/float] 数字、含千分分隔符数字
:return: string 大写数字
"""# 格式化输入内容,去掉含千分分隔符,去掉空格,去掉转义符号
num =str(num).replace(',','').replace(' ','').strip()
ch_num =['零','壹','贰','叁','肆','伍','陆','柒','捌','玖','拾']
s_unit =['','拾','佰','仟']# 不够的话可以继续往后面加
b_unit =['','万','亿','兆','京','垓','秭','穰','沟','涧','正','载','极']
float_cont =''# 小数部分if'.'in num:
float_cont +=''.join([ch_num[int(fc)]for fc inf'{num}'.split('.')[1]])
num =f'{num}'.split('.')[0]# 整数部分
numlist =list(map(int,str(num)))
numlist.reverse()
l =[]
j =0for i inrange(0,len(numlist),4):
p =[]ifsum(numlist[i:i+4]):for ii inrange(0,4):if(i+ii)<len(numlist):if numlist[i+ii]:
p.append([s_unit[ii], ch_num[numlist[i+ii]]])else:if p and p[-1]!=['零']:
p.append(['零'])if j <len(b_unit):
l.append([b_unit[j]]+p)else:return"数字太大,超出计量范围!!"else:if l and l[-1]!=['零']and l[-1][-1]!=['零']:
l.append(['零'])
j +=1
l =[c for a in l for b in a for c in b if c]
l.reverse()
l =''.join(l)return l +'点'+ float_cont if float_cont !=''else l
if __name__ =='__main__':print(convert(124134.777))