/// <summary>
    /// 本类实现阿拉伯数字到大写中文的转换
    /// 该类没有对非法数字进行判别,请事先自己判断数字是否合法
    /// </summary>
    public class ChineseNum
    {

   //小写转大写
        public static string GetChineseNum(string p_num)
        {
            ChineseNum cn = new ChineseNum();

return cn.NumToChn(p_num);
        }

   //小写金额转大写金额

public static string GetUpperMoney(double p_Money)
        {
            ChineseNum cn = new ChineseNum();

return cn.GetMoneyChinese(p_Money);
        }

//转换数字
        private char CharToNum(char x)
        {
            string stringChnNames = "零一二三四五六七八九";
            string stringNumNames = "0123456789";
            return stringChnNames[stringNumNames.IndexOf(x)];
        }

//转换万以下整数
        private string WanStrToInt(string x)
        {
            string[] stringArrayLevelNames = new string[4] { "", "十", "百", "千" };
            string ret = "";
            int i;
            for (i = x.Length - 1; i >= 0; i--)
                if (x[i] == '0')
                {
                    ret = CharToNum(x[i]) + ret;
                }
                else
                {
                    ret = CharToNum(x[i]) + stringArrayLevelNames[x.Length - 1 - i] + ret;
                }
            while ((i = ret.IndexOf("零零")) != -1)
            {
                ret = ret.Remove(i, 1);
            }
            if (ret[ret.Length - 1] == '零' && ret.Length > 1)
            {
                ret = ret.Remove(ret.Length - 1, 1);
            }
            if (ret.Length >= 2 && ret.Substring(0, 2) == "一十")
            {
                ret = ret.Remove(0, 1);
            }
            return ret;
        }

//转换整数
        private string StrToInt(string x)
        {
            int len = x.Length;
            string ret, temp;
            if (len <= 4)
            {
                ret = WanStrToInt(x);
            }
            else if (len <= 8)
            {
                ret = WanStrToInt(x.Substring(0, len - 4)) + "万";
                temp = WanStrToInt(x.Substring(len - 4, 4));
                if (temp.IndexOf("千") == -1 && temp != "")
                    ret += "零" + temp;
                else
                    ret += temp;
            }
            else
            {
                ret = WanStrToInt(x.Substring(0, len - 8)) + "亿";
                temp = WanStrToInt(x.Substring(len - 8, 4));
                if (temp.IndexOf("千") == -1 && temp != "")
                {
                    ret += "零" + temp;
                }
                else
                {
                    ret += temp;
                }
                ret += "万";
                temp = WanStrToInt(x.Substring(len - 4, 4));
                if (temp.IndexOf("千") == -1 && temp != "")
                {
                    ret += "零" + temp;
                }
                else
                {
                    ret += temp;
                }
            }
            int i;
            if ((i = ret.IndexOf("零万")) != -1)
            {
                ret = ret.Remove(i + 1, 1);
            }
            while ((i = ret.IndexOf("零零")) != -1)
            {
                ret = ret.Remove(i, 1);
            }
            if (ret[ret.Length - 1] == '零' && ret.Length > 1)
            {
                ret = ret.Remove(ret.Length - 1, 1);
            }
            return ret;
        }
        //转换小数
        private string StrToDouble(string x)
        {
            string ret = "";
            for (int i = 0; i < x.Length; i++)
            {
                ret += CharToNum(x[i]);
            }
            return ret;
        }
        private string NumToChn(string x)
        {
            if (x.Length == 0)
            {
                return "";
            }
            string ret = "";
            if (x[0] == '-')
            {
                ret = "负";
                x = x.Remove(0, 1);
            }
            if (x[0].ToString() == ".")
            {
                x = "0" + x;
            }
            if (x[x.Length - 1].ToString() == ".")
            {
                x = x.Remove(x.Length - 1, 1);
            }
            if (x.IndexOf(".") > -1)
            {
                ret += StrToInt(x.Substring(0, x.IndexOf("."))) + "点" + StrToDouble(x.Substring(x.IndexOf(".") + 1));
            }
            else
            {
                ret += StrToInt(x);
            }
            return ret;
        }

   //金额转换

   private string GetMoneyChinese(Double Money)
        {
            int i;
            string mstrSource;

if (Money == 0)
            {
                return "";
            }
            mstrSource = Money.ToString("#0.00");
            i = mstrSource.IndexOf(".");
            if (i > 0) { mstrSource = mstrSource.Replace(".", ""); }
            if (mstrSource.Substring(0, 1) == "0") { mstrSource = mstrSource.Remove(0, 1); }

mstrSource = NumstrToChinese(mstrSource);
            if (mstrSource.Length == 0) { return ""; }
            //负
            if (Money < 0)
            {
                mstrSource = "负" + mstrSource;
            }
            mstrSource = mstrSource.Replace("0", "零");
            mstrSource = mstrSource.Replace("1", "壹");
            mstrSource = mstrSource.Replace("2", "贰");
            mstrSource = mstrSource.Replace("3", "叁");
            mstrSource = mstrSource.Replace("4", "肆");
            mstrSource = mstrSource.Replace("5", "伍");
            mstrSource = mstrSource.Replace("6", "陆");
            mstrSource = mstrSource.Replace("7", "柒");
            mstrSource = mstrSource.Replace("8", "捌");
            mstrSource = mstrSource.Replace("9", "玖");
            mstrSource = mstrSource.Replace("M", "亿");
            mstrSource = mstrSource.Replace("W", "万");
            mstrSource = mstrSource.Replace("S", "仟");
            mstrSource = mstrSource.Replace("H", "佰");
            mstrSource = mstrSource.Replace("T", "拾");
            mstrSource = mstrSource.Replace("Y", "圆");
            mstrSource = mstrSource.Replace("J", "角");
            mstrSource = mstrSource.Replace("F", "分");
            if (mstrSource.Substring(mstrSource.Length - 1, 1) != "分")
            {
                mstrSource = mstrSource + "整";
            }
            return mstrSource;
        }
        //金额转换
        private string NumstrToChinese(string numstr)
        {
            int i;
            int j;
            string mstrChar;
            string[] mstrFlag = new string[4];
            string mstrReturn = "";
            bool mblnAddzero = false;

mstrFlag[0] = "";
            mstrFlag[1] = "T";
            mstrFlag[2] = "H";
            mstrFlag[3] = "S";

for (i = 1; i <= numstr.Length; i++)
            {
                j = numstr.Length - i;
                mstrChar = numstr.Substring(i - 1, 1);
                if (mstrChar != "0" && j > 1) { mstrReturn = mstrReturn + mstrChar + mstrFlag[(j - 2) % 4]; }
                if (mstrChar == "0" && mblnAddzero == false)
                {
                    mstrReturn = mstrReturn + "0";
                    mblnAddzero = true;
                }
                if (j == 14)
                {
                    if (mstrReturn.Substring(mstrReturn.Length - 1) == "0")
                    { mstrReturn = mstrReturn.Substring(0, mstrReturn.Length - 1) + "W0"; }
                    else
                    { mstrReturn = mstrReturn + "W"; }
                }
                if (j == 2)
                {
                    if (mstrReturn.Substring(mstrReturn.Length - 1, 1) == "0")
                    { mstrReturn = mstrReturn.Substring(0, mstrReturn.Length - 1) + "Y0"; }
                    else
                    { mstrReturn = mstrReturn + "Y"; }
                    //元
                }
                if (j == 6)
                {
                    if (mstrReturn.Length > 2)
                    {
                        if (mstrReturn.Substring(mstrReturn.Length - 2) != "M0")
                        {
                            if (mstrReturn.Substring(mstrReturn.Length - 1) == "0")
                            { mstrReturn = mstrReturn.Substring(0, mstrReturn.Length - 1) + "W0"; }
                            else
                            { mstrReturn = mstrReturn + "W"; }
                        }
                    }
                    else
                    {
                        if (mstrReturn.Substring(mstrReturn.Length - 1) == "0")
                        { mstrReturn = mstrReturn.Substring(0, mstrReturn.Length - 1) + "W0"; }
                        else
                        { mstrReturn = mstrReturn + "W"; }
                    }
                }
                if (j == 10)
                {
                    if (mstrReturn.Substring(mstrReturn.Length - 1) == "0")
                    { mstrReturn = mstrReturn.Substring(0, mstrReturn.Length - 1) + "M0"; }
                    else
                    { mstrReturn = mstrReturn + "M"; }
                }
                if (j == 0 && mstrChar != "0") { mstrReturn = mstrReturn + mstrChar + "F"; }
                if (j == 1 && mstrChar != "0") { mstrReturn = mstrReturn + mstrChar + "J"; }
                if (mstrChar != "0") { mblnAddzero = false; }
            }

if (mstrReturn.Substring(0, 1) == "1" && mstrReturn.Substring(1, 1) == mstrFlag[1]) { mstrReturn = mstrReturn.Substring(1); }
            if (mstrReturn.Substring(mstrReturn.Length - 1, 1) == "0") { mstrReturn = mstrReturn.Substring(0, mstrReturn.Length - 1); }
            if (mstrReturn.Substring(0, 1) == "0") { mstrReturn = mstrReturn.Substring(1); }
            if (mstrReturn.Substring(mstrReturn.Length - 1, 1) == "M" || mstrReturn.Substring(mstrReturn.Length - 1, 1) == "W" || mstrReturn.Substring(mstrReturn.Length - 1, 1) == "S" || mstrReturn.Substring(mstrReturn.Length - 1, 1) == "H" || mstrReturn.Substring(mstrReturn.Length - 1, 1) == "T") { mstrReturn = mstrReturn + "Y"; }
            return mstrReturn;
        }
    }

C#实现阿拉伯数字(小写金额)到大写中文(大写金额)的转换的更多相关文章

  1. C#:小写金额转换为大写

    #region 小写金额转换为大写 public static string CurrToChnNum(double Currnum) { string sResult = ""; ...

  2. jsp页面输入小写金额转大写

    <script> function chineseNumber(num){ if (isNaN(num) || num > Math.pow(10, 12)) return &quo ...

  3. php小写金额转大写

    public static function amountInWords($num) {         if (!is_numeric($num) || empty($num))           ...

  4. js 小写金额转大写

    function smalltoBIG(n) { var fraction = ['角', '分']; var digit = ['零', '壹', '贰', '叁', '肆', '伍', '陆', ...

  5. js 人民币小写金额转换为大写

    function smalltoBIG(n) { var fraction = ['角', '分']; var digit = ['零', '壹', '贰', '叁', '肆', '伍', '陆', ...

  6. JS实现 阿拉伯数字金额转换为中文大写金额 可以处理负值

    JS实现 阿拉伯数字金额转换为中文大写金额 可以处理负值 //************************* 把数字金额转换成中文大写数字的函数(可处理负值) ****************** ...

  7. SQL函数:小写金额转换成大写

    /********************************************************作者:版本:1.0创建时间:20020227修改时间:功能:小写金额转换成大写参数:n ...

  8. JavaScript将小写金额转换成大写

    //num为小写金额,单位元 changeMoney(num) { if(isNaN(num))return ""; var strPrefix=""; if( ...

  9. php把阿拉伯数字转为银行数字大写

    php把阿拉伯数字转为银行数字大写 前言:之前在做一个外贸公司的询报价系统时用到了记录关于金额的数据,一般阿拉伯数字都需要转为银行使用的大写数字,在这简单记录一下 /* * 数字金额转换成中文大写金额 ...

随机推荐

  1. mybatis配置-返回date类型丢失时间

    此博客仅作于平时开发所遇到的问题记录,不做他用,描述可能不好,自己看懂即可~~ resultMap配置返回时间类型时,发现数据库时间是精确到秒的,但是返回给javabean之后丢失时分秒的信息,只有日 ...

  2. JS URL参数传递 谷歌乱码解决

    //第一个页面 var name=encodeURIComponent("参数"); var url="test1.html?name="+name; //第二 ...

  3. ffmpeg转码MPEG2-TS的音视频同步机制分析

    http://blog.chinaunix.net/uid-26000296-id-3483782.html 一.FFmpeg忽略了adaptation_field()数据 FFmpeg忽略了包含PC ...

  4. Android网络通信android-async-http入门

    android-async-http入门 门免费链接分享前:http://pan.baidu.com/s/1mg9SvgO 密码:cgg7 API原文:http://loopj.com/android ...

  5. linux命令之crontab定时执行任务

    一.crond简介 crond 是linux下用来周期性的执行某种任务或等待处理某些事件的一个守护进程,与windows下的计划任务类似,当安装完成操作系统后,默认会安装此服务 工具,并且会自动启动c ...

  6. crontab的相关设置&amp;linux定时备份数据库

    对于才了解crontab的人来说,应该按照以下的步骤来设置crontab 1.首先要检查是否装了crontab http://blog.sina.com.cn/s/blog_4881040d01011 ...

  7. 判断值是否为undefined

    可以使用 Ext.isDefined( value ) 这个函数, 也可以使用下面代码来进行实现: /** 判断传入的值是否 为undefined */ function isUndefined(va ...

  8. HoloLens开发手记 - HoloLens shell概述 HoloLens shell overview

    使用HoloLens时,shell是由你周围的世界和来自系统的全息图像构成.我们将这种空间成为混合世界(mixed world). shell包含了一个可以让你将全息图像和应用放置在世界中的开始菜单( ...

  9. vscode中iframe的使用

    vscode中iframe由于某种原因不支持本地页面,比如<iframe src ="index.html" width="300" height=&qu ...

  10. [daily][CentOS][SELinux]用key免登陆不成功,原来是SElinux在搞事情

    为了提高效率,一般情况下,会把公钥放到sshd主机的 $HOME/.ssh/authorized_keys 文件内. 把私钥放在client的 $HOME/.ssh/ 下. 然后就可以免密登录了.然而 ...