number=("零","壹","贰","叁","肆","伍","陆","柒","捌","玖")
units=("拾","佰","千","万","亿")
last=0
last1=0
def handle(temp=101,flag=0):
global last,last1
if int(temp/1e4)!=0:
handle(int(temp/1e4),1)
for i in range(3,0,-1):
temp1=(int)(temp/(10**i))%10
temp-=temp1*(10**i)
if temp1!=0:
if(last==1):
print(end="零")
print(number[int(temp1)],end="")#number
print(units[int(i)-1],end="")#unit
last=0
last1=1
elif last==0 and last1==1:
last=1
last1=0
if int(temp%10)!=0:
if(last==1):
print(end="零")
last=0
last1=1
print(number[int(temp%10)],end="")#left number
if flag==1:
print(end="万")#left number
if __name__=="__main__":
money=input("Money:\n")
print("Capital:")
count=int(len(money)/8)
cut=len(money)%8
for i in range(count+1):
if i==0:
temps=int(money[0:cut])
else:
temps=int(money[cut+8*(i-1):cut+8*i])
handle(temps,0)
print("亿"*(count-i),end="")
pass
#100000000098877678779567894567845678589567863784340000001
python 转整型数字为中文大写,不限位数
最新推荐文章于 2024-08-22 08:21:56 发布
该代码实现将输入的数字转换成中文大写,适用于处理货币等需要中文数字表示的场景。通过递归处理每一位数字,并结合不同位数的单位进行输出。在主函数中,先将输入的字符串按每8位切割,然后逐个处理并输出。
1417

被折叠的 条评论
为什么被折叠?



