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];
        }
    }

你可能感兴趣的:(C#,c#,开发语言)