ASP.NET 实现人民币大写转换函数

转换函数如下代码所示:

        public static string GetBig(string num)
        {
            string result=null;
            string chNum = "零壹贰叁肆伍陆柒捌玖";//定义好大写的数字
            string zheng = "元拾佰仟万拾佰仟亿拾佰仟万";//定义好数位,从小到大排
            string xiaoshu = "角分";//把整数和小数分开处理
            if (num.IndexOf('.') != -1)//检测用户输入中是否包含小数点
            {
                string[] temp = num.Split('.');//把用户输入的字符
                int index = temp[0].Length-1;
                for (int i = 0; i < temp[0].Length; i++)
                {
                    result += chNum[Convert.ToInt32(temp[0][i].ToString())];
                    result += zheng[index];
                    index--;
                }
                if (temp[1].Length>0)
                {
                    for (int i = 0; i < temp[1].Length; i++)
                    {
                        result += chNum[Convert.ToInt32(temp[1][i].ToString())];
                        result += xiaoshu[i];
                    }
                }
            }
            else
            {
                int index = num.Length-1;
                for (int i = 0; i < num.Length; i++)
                {
                    result += chNum[Convert.ToInt32(num[i].ToString())];
                    result += zheng[index];
                    index--;
                }
            }
            return result;
        }

调用: GetBig("526487.25");

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值