人民币阿拉伯数字转中文大写的几种特殊情况

人民币阿拉伯数字转中文大写的几种特殊情况

  1. 连着多个‘0’读作一个“零”
  2. 开头数字是‘1’时省略“壹”,如‘11’读作“拾壹”而不是“壹拾壹”
  3. 小数为‘00’时读作“整”
  4. 小数为‘0X’时读作“X分”
  5. 小数为‘X0’时读锁“X角”
  6. 小数为‘XX’时读作“X角X分”
  7. 整数部分仅为‘1’时,‘壹’不省略
  8. 整数部分为‘0’时,直接读小数,省略“元”

华为机试人民币转换

import re

while True:
    try:
        al = ["零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"]
        de = ["元", "拾", "佰", "仟", "万", "拾", "佰", "仟", "亿", "拾", "佰", "仟", "万亿", "拾", "佰", "仟"]
        res = '人民币'
        shu = input().split('.')
        data = shu[0]
        if shu[0][0] == '0':
            res = res
        elif shu[0][0] == '1' and len(shu[0]) == 1:
            res = res + "壹" + "元"
        else:
            for i in range(len(data)):
                if len(res)>0 and res[-1] == "零" and data[i] == '0':
                    continue
                elif data[i] == '0':
                    res = res + al[int(data[i])]
                elif i == 0 and data[i] == '1':
                    res = res + de[len(data) - i - 1]
                else:
                    res = res + al[int(data[i])] + de[len(data)-i-1]
        data = shu[1]
        if data[0] != '0' and data[1] == '0':
            res = res + al[int(data[0])] + '角'
        elif data[0] == '0' and data[1] != '0':
            if shu[0][0] == '0':
                res = res + al[int(data[1])] + '分'
            else:
                res = res + al[int(data[1])] + '分'
        elif data[0] != '0' and data[1] != '0':
            res = res + al[int(data[0])] + '角' + al[int(data[1])] + '分'
        else:
            res = res + '整'

        print(res)
    except:
        break

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值