/// <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. SQL标量值函数:小写金额转大写

    我们日常开发业务系统中,作为统计报表中,特别是财务报表,显示中文金额经常遇到. 转换大小写的方法有很多,以下是从数据库函数方面解决这一问题. 效果如图: 调用:SELECT dbo.[Fn_Conve ...

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

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

  4. php小写金额转大写

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

  5. js 小写金额转大写

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

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

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

  7. JS将人民币小写金额转换为大写

    /** 数字金额大写转换(可以处理整数,小数,负数) */ function smalltoBIG(n) { var fraction = ['角', '分']; var digit = ['零', ...

  8. java将小写金额转换为大写的工具类

    public class Tool {             private static final String UNIT = "万千佰拾亿千佰拾万千佰拾元角分";      ...

  9. 【转】Delphi货币类型转中文大写金额

    unit TU2.Helper.Currency; interface ): string; ): string; implementation uses System.SysUtils, Syste ...

随机推荐

  1. mysql error 1130 hy000:Host 'localhost' is not allowed to connect to this mysql server 解决方案

    ERROR 1130 (HY000): Host 'localhost' is not allowed to connect to this MySQL server D:\Wamp\mysql-\b ...

  2. 浅谈PHP7的新特性

    我以前用过的php的最高版本是php5.6.在换新工作之后,公司使用的是PHP7.据说PHP7的性能比之前提高很多.下面整理下php7的新特性.力求简单了解.不做深入研究. 1.变量类型声明 函数的参 ...

  3. AmCharts 对数据排序后展示

    在官网看到的例子 给chart添加一个排序功能的handler AmCharts.addInitHandler( function(chart){ if (chart.orderByField === ...

  4. Scala 运算符和集合转换操作示例

    Scala是数据挖掘算法领域最有力的编程语言之一,语言本身是面向函数,这也符合了数据挖掘算法的常用场景:在原始数据集上应用一系列的变换,语言本身也对集合操作提供了众多强大的函数,本文将以List类型为 ...

  5. 关于form表单上传图片的一些记录

    jsp页面 <form class="form-horizontal" role="form" action="brandAction_addB ...

  6. 【转载】quickLayout.css-快速构建结构兼容的web页面

    文章转载自 张鑫旭-鑫空间-鑫生活 http://www.zhangxinxu.com/wordpress/ 原文链接:http://www.zhangxinxu.com/wordpress/?p=4 ...

  7. Java继承--子类的实例化过程

    一个对象的实例化过程: Person p = new Person(); 1,JVM会读取指定的路径下的Person.class文件,并加载进内存,并会先加载Person的父类(如果有直接的父类的情况 ...

  8. win10 uwp 反射

    本文在h神的指导下完成. 反射是强大的好用的,我们可以添加新功能不修改之前的代码,通过使用反射得到. 本文下面和大家说如何做一个和WPF一样的反射功能,如何才能获的 UWP 程序集所有类. 先来说下反 ...

  9. shell编程/字库裁剪(1)

    我写这个帖子的意图,在于三个: 1.用代码生成代码的思维. 2.shell编程的思路. 3.裁剪字库的具体程序. 我打算分为三节来说: 第一节讲裁剪裁剪词库的意义以及使用场合: 第二节讲如何用shel ...

  10. Sql语句备份Sqlserver数据库

    BACKUP DATABASE [POS_YiZhuang]TODISK = N'C:\数据库\POS_YiZhuang2016-09-20-3.bak'WITHNAME = N'POS_YiZhua ...