知识大全 C#实现阿拉伯数字到大写中文的转换

Posted 阿拉伯数字

篇首语:敢说敢作敢为, 无怨无恨无悔。本文由小常识网(cha138.com)小编为大家整理,主要介绍了知识大全 C#实现阿拉伯数字到大写中文的转换相关的知识,希望对你有一定的参考价值。

C#实现阿拉伯数字到大写中文的转换  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!

  /// <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 = ;            return stringChnNames[stringNumNames IndexOf(x)];       

  //转换万以下整数        private string WanStrToInt(string x)                    string[] stringArrayLevelNames = new string[ ] 十 百 千 ;            string ret = ;            int i;            for (i = x Length ; i >= ; i )                if (x[i] == )                                    ret = CharToNum(x[i]) + ret;                                else                                    ret = CharToNum(x[i]) + stringArrayLevelNames[x Length i] + ret;                            while ((i = ret IndexOf( 零零 )) != )                            ret = ret Remove(i );                        if (ret[ret Length ] == 零 && ret Length > )                            ret = ret Remove(ret Length );                        if (ret Length >= && ret Substring( ) == 一十 )                            ret = ret Remove( );                        return ret;       

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

  //金额转换       

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

  if (Money == )                            return ;                        mstrSource = Money ToString( # );            i = mstrSource IndexOf( );            if (i > ) mstrSource = mstrSource Replace( );             if (mstrSource Substring( ) == ) mstrSource = mstrSource Remove( );

  mstrSource = NumstrToChinese(mstrSource);            if (mstrSource Length == ) return ;             //负            if (Money < )                            mstrSource = 负 + mstrSource;                        mstrSource = mstrSource Replace( 零 );            mstrSource = mstrSource Replace( 壹 );            mstrSource = mstrSource Replace( 贰 );            mstrSource = mstrSource Replace( 三 );            mstrSource = mstrSource Replace( 肆 );            mstrSource = mstrSource Replace( 伍 );            mstrSource = mstrSource Replace( 陆 );            mstrSource = mstrSource Replace( 柒 );            mstrSource = mstrSource Replace( 捌 );            mstrSource = mstrSource Replace( 玖 );            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 ) != 分 )                            mstrSource = mstrSource + 整 ;                        return mstrSource;                //金额转换        private string NumstrToChinese(string numstr)                    int i;            int j;            string mstrChar;            string[] mstrFlag = new string[ ];            string mstrReturn = ;            bool mblnAddzero = false;

  mstrFlag[ ] = ;            mstrFlag[ ] = T ;            mstrFlag[ ] = H ;            mstrFlag[ ] = S ;

  for (i = ; i <= numstr Length; i++)                            j = numstr Length i;                mstrChar = numstr Substring(i );                if (mstrChar != && j > ) mstrReturn = mstrReturn + mstrChar + mstrFlag[(j ) % ];                 if (mstrChar == && mblnAddzero == false)                                    mstrReturn = mstrReturn + ;                    mblnAddzero = true;                                if (j == )                                    if (mstrReturn Substring(mstrReturn Length ) == )                    mstrReturn = mstrReturn Substring( mstrReturn Length ) + W ;                     else                    mstrReturn = mstrReturn + W ;                                 if (j == )                                    if (mstrReturn Substring(mstrReturn Length ) == )                    mstrReturn = mstrReturn Substring( mstrReturn Length ) + Y ;                     else                    mstrReturn = mstrReturn + Y ;                     //元                                if (j == )                                    if (mstrReturn Length > )                                            if (mstrReturn Substring(mstrReturn Length ) != M )                                                    if (mstrReturn Substring(mstrReturn Length ) == )                            mstrReturn = mstrReturn Substring( mstrReturn Length ) + W ;                             else                            mstrReturn = mstrReturn + W ;                                                                 else                                            if (mstrReturn Substring(mstrReturn Length ) == )                        mstrReturn = mstrReturn Substring( mstrReturn Length ) + W ;                         else                        mstrReturn = mstrReturn + W ;                                                     if (j == )                                    if (mstrReturn Substring(mstrReturn Length ) == )                    mstrReturn = mstrReturn Substring( mstrReturn Length ) + M ;                     else                    mstrReturn = mstrReturn + M ;                                 if (j == && mstrChar != ) mstrReturn = mstrReturn + mstrChar + F ;                 if (j == && mstrChar != ) mstrReturn = mstrReturn + mstrChar + J ;                 if (mstrChar != ) mblnAddzero = false;            

cha138/Article/program/net/201311/13523

相关参考

知识大全 C#纯数学方法递归实现货币数字转换中文

C#纯数学方法递归实现货币数字转换中文  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!  最近由于项

知识大全 在PB中实现数字的英文大写和中文大写[3]

在PB中实现数字的英文大写和中文大写[3]  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧! 

知识大全 在PB中实现数字的英文大写和中文大写[2]

在PB中实现数字的英文大写和中文大写[2]  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧! 

知识大全 在PB中实现数字的英文大写和中文大写[1]

在PB中实现数字的英文大写和中文大写[1]  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧! 

知识大全 将数字转为中文金额的大写方式

  publicclassTransRMB  /**  *测试程序的可行性  *@paramargs  */  publicstaticvoidmain(String[]args)  Systemou

知识大全 Java转换大写金额的代码

Java转换大写金额的代码  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!  此代码根据网上搜集到的

知识大全 如何将C#时间格式转换为中文格式

如何将C#时间格式转换为中文格式  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!  首先使用Java

知识大全 如何在ORACLE中实现人民币大写的转换

如何在ORACLE中实现人民币大写的转换  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!  ORAC

知识大全 要开一张现金支票 日期为12月30日,正确的大写是怎么写的?

要开一张现金支票日期为12月30日,正确的大写是怎么写的?贰零壹零年壹拾贰月零叁拾日今天我也要开一张开一张现金支票,日期是2011年4月25日,日期该怎么正确填写?左边存根联直接写小写阿拉伯数字:20

知识大全 支票日期中日期是30日,大写该如何写呢

支票日期中日期是30日,大写该如何写呢?零叁拾日吗?,支票日期写零贰拾叁日能受理吗支票日期中的30日,前面不需要加零,直接写叁拾日即可。详见如下:支票日期填写:出票日期(大写)、数字必须大写,大写数字