python实现⼈民币⾦额⼤写转⼩写数字⽀持万亿以内的转换,如果你有超出这个范围的钱,给我亿点点,求你了!
import re
def aoligeiganle(amount):
chinese_num ={'零':0,'壹':1,'贰':2,'叁':3,'肆':4,'伍':5,'陆':6,'柒':7,'捌':8,'玖':9}
chinese_amount ={'分':0.01,'⾓':0.1,'元':1,'拾':10,'佰':100,'仟':1000,'圆':1}
amount_float =0
if'亿'in amount:
yi = re.match(r'(.+)亿.*', amount).group(1)
amount_yi =0
for i in chinese_amount:
if i in yi:
amount_yi += chinese_num[yi[yi.index(i)-1]]* chinese_amount[i]
if yi[-1]in chinese_num.keys():
amount_yi += chinese_num[yi[-1]]
amount_float += amount_yi *100000000
amount = re.sub(r'.+亿','', amount, count=1)
if'万'in amount:
wan = re.match(r'(.+)万.*', amount).group(1)
amount_wan =0
python货币转换for i in chinese_amount:
if i in wan:
amount_wan += chinese_num[wan[wan.index(i)-1]]* chinese_amount[i]
if wan[-1]in chinese_num.keys():
amount_wan += chinese_num[wan[-1]]
amount_float += amount_wan *10000
amount = re.sub(r'.+万','', amount, count=1)
amount_yuan =0
for i in chinese_amount:
if i in amount:
if amount[amount.index(i)-1]in chinese_num.keys():
amount_yuan += chinese_num[amount[amount.index(i)-1]]* chinese_amount[i]
amount_float += amount_yuan
return amount_float
加油,奥⼒给!

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。