C# 大写金额转换

public class PMAmount
    {
        private int _cent;
        private int _jiao;
        private int _yuan;
        private int _ten;
        private int _hundred;
        private int _thousand;
        private int _wan;
        private int _shiWan;
        private int _baiWan;

        public PMAmount(decimal amount)
        {
            decimal absAmount = Math.Abs(amount);
            ConvertToAllIntNum(absAmount);
            ConvertToAllStrNum(amount);
        }

        public string Fu { get; set; }

        public string Cent { get; set; }

        public string Jiao { get; set; }

        public string Yuan { get; set; }

        public string Ten { get; set; }

        public string Hundred { get; set; }

        public string Thousand { get; set; }

        public string Wan { get; set; }

        public string ShiWan { get; set; }

        public string BaiWan { get; set; }

        private void ConvertToAllIntNum(decimal m)
        {
            _baiWan = (int)Math.Floor(m / 1000000);
            _shiWan = (int)Math.Floor((m - _baiWan * 1000000) / 100000);
            _wan = (int)Math.Floor((m - _baiWan * 1000000 - _shiWan * 100000) / 10000);
            _thousand = (int)Math.Floor((m - _baiWan * 1000000 - _shiWan * 100000 - _wan * 10000) / 1000);
            _hundred = (int)Math.Floor((m - _baiWan * 1000000 - _shiWan * 100000 - _wan * 10000 - _thousand * 1000) / 100);
            _ten = (int)Math.Floor((m - _baiWan * 1000000 - _shiWan * 100000 - _wan * 10000 - _thousand * 1000 - _hundred * 100) / 10);
            _yuan = (int)Math.Floor((m - _baiWan * 1000000 - _shiWan * 100000 - _wan * 10000 - _thousand * 1000 - _hundred * 100 - _ten * 10));
            _jiao = (int)Math.Floor((m - Math.Floor(m)) * 10);
            _cent = (int)Math.Floor((m - Math.Floor(m) - _jiao * 0.1m) * 100);
        }

        private void ConvertToAllStrNum(decimal m)
        {
            BaiWan = _baiWan != 0 ? GetIntCapital(_baiWan) : "";
            ShiWan = _shiWan != 0 ? GetIntCapital(_shiWan) : (_baiWan > 0 ? "零" : "");
            Wan = _wan != 0 ? GetIntCapital(_wan) : (_baiWan + _shiWan > 0 ? "零" : "");
            Thousand = _thousand != 0 ? GetIntCapital(_thousand) : (_baiWan + _shiWan + _wan > 0 ? "零" : "");
            Hundred = _hundred != 0 ? GetIntCapital(_hundred) : (_baiWan + _shiWan + _wan + _thousand > 0 ? "零" : "");
            Ten = _ten != 0 ? GetIntCapital(_ten) : (_baiWan + _shiWan + _wan + _thousand + _hundred > 0 ? "零" : "");
            Yuan = _yuan != 0 ? GetIntCapital(_yuan) : (_baiWan + _shiWan + _wan + _thousand + _hundred + _ten > 0 ? "零" : "");
            Jiao = _jiao != 0 ? GetIntCapital(_jiao) : "零";
            Cent = _cent != 0 ? GetIntCapital(_cent) : "零";
            if (m < 0) Fu = "负";
        }

        private string GetIntCapital(int num)
        {
            string[] numStr = { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" };
            return numStr[num];
        }
    }
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值