• 数字金额转换大写人民币


     

    using System;
    using System.Collections.Generic;
    using System.Text;

    namespace PublicClass
    {
        /// <summary>
        /// Copyright(c) 2008~2011 KingBoy Software Co.,Ltd
        /// FileName:大写人民币类
        /// Author:KingBoy  Version:1.0.0.0  Date:2009-3-05
        /// Description:提供将数值型输入转变成人民币大写的标准类。 
        /// </summary>
        public class ChineseMoney
        {
            private decimal dMoney = 0; //金额
            /// <summary>
            /// 设置或获取金额
            /// </summary>
            public decimal money
            {
                get { return dMoney; }
                set { dMoney = value; }
            }
            public ChineseMoney(decimal m)
            {
                dMoney = m;
            }
            /// <summary>
            /// 获取金额大写
            /// </summary>
            /// <returns></returns>
            public string getChineseMoney()
            {
                try
                {
                    string strcmd = Convert.ToString(dMoney); //将金额转换为字符串型
                    string[] temp = strcmd.Split('.');
                    string[] integer ={"元","拾","佰","仟","万","拾万","佰万","仟万","亿","拾亿","佰亿","仟亿","万亿","亿亿" };
                    string[] infrex ={"角","分" };
                    string[] data ={"零","壹","贰","叁","肆","伍","陆","柒","捌","玖" };
                    string result = "";
                    if (temp.Length > 0)
                    {
                        /*
                         处理整数部分
                         */
                        string ch = "";
                        for (int i = 0; i < temp[0].Length; i++)
                        {
                            switch (Convert.ToInt32(temp[0].Substring(i, 1)))
                            {
                                case 0:
                                    ch = data[0]; break;
                                case 1:
                                    ch = data[1]; break;
                                case 2:
                                    ch = data[2]; break;
                                case 3:
                                    ch = data[3]; break;
                                case 4:
                                    ch = data[4]; break;
                                case 5:
                                    ch = data[5]; break;
                                case 6:
                                    ch = data[6]; break;
                                case 7:
                                    ch = data[7]; break;
                                case 8:
                                    ch = data[8]; break;
                                case 9:
                                    ch = data[9]; break;
                                default:
                                    ch = ""; break;
                            }
                            if (Convert.ToInt32(temp[0].Substring(i, 1)) > 0)
                                result =  result+ ch +integer[temp[0].Length-i-1];
                            else
                                result = result +ch ;
                        }
                    }
                      if (temp.Length > 1) //处理小数部分
                      { 
                         string ch = "";
                      for (int i = 0; i < temp[1].Length; i++)
                      {
                          switch (Convert.ToInt32(temp[1].Substring(i, 1)))
                          {
                              case 0:
                                  ch = data[0]; break;
                              case 1:
                                  ch = data[1]; break;
                              case 2:
                                  ch = data[2]; break;
                              case 3:
                                  ch = data[3]; break;
                              case 4:
                                  ch = data[4]; break;
                              case 5:
                                  ch = data[5]; break;
                              case 6:
                                  ch = data[6]; break;
                              case 7:
                                  ch = data[7]; break;
                              case 8:
                                  ch = data[8]; break;
                              case 9:
                                  ch = data[9]; break;
                              default:
                                  ch = ""; break;
                          }
                          if (Convert.ToInt32(temp[1].Substring(i, 1)) > 0)
                              result =result+ch+infrex[i] ;
                          else
                              result = result +ch;
                      }

                    }
                    return result;

                }
                catch (Exception)
                {
                    return "转换失败!";
                }
            }
        }
    }

  • 相关阅读:
    【android tools】内存、网络、界面性能响应优化的工具
    mysql命令(数据库备份与恢复)
    mysql中一些简单但是新手容易犯的错误
    Mysql bench执行sql语句批量操作数据所遇到的问题
    Excel “此单元格中的数字为文本格式,或者其前面有撇号” 设成数字格式
    VC程序异常中断的原因
    vs dump调试
    winsock.h与winsock2.h出现重定义或不同的链接
    QT中QString与string的转化,解决中文乱码问题
    线程中CreateEvent和SetEvent及WaitForSingleObject的用法
  • 原文地址:https://www.cnblogs.com/ysz12300/p/5507616.html
Copyright © 2020-2023  润新知