读书人

200 分,doluble 类型,转换为汉字的最优

发布时间: 2012-01-12 22:11:58 作者: rapoo

200 分,doluble 类型,转换为汉字的最优方法.
很久以前在论坛上看到过类似的问题,其他看到了一种很精妙的方法,但是现在已经找不到那篇了.所以发贴求助,首先谢谢大家 .

例如: 192.37 得到: 壹佰玖拾贰元叁角柒分


算法精妙的回贴有高分相赠..谢谢

[解决办法]
同学习
[解决办法]

C# code
public static string CmycurD(decimal num)        {            string str1 = "零壹贰叁肆伍陆柒捌玖";            //0-9所对应的汉字            string str2 = "万仟佰拾亿仟佰拾万仟佰拾元角分"; //数字位所对应的汉字            string str3 = "";    //从原num值中取出的值            string str4 = "";    //数字的字符串形式            string str5 = "";  //人民币大写金额形式            int i;    //循环变量            int j;    //num的值乘以100的字符串长度            string ch1 = "";    //数字的汉语读法            string ch2 = "";    //数字位的汉字读法            int nzero = 0;  //用来计算连续的零值是几个            int temp;            //从原num值中取出的值                    num = Math.Round(Math.Abs(num),2);    //将num取绝对值并四舍五入取2位小数            str4 = ((long)(num*100)).ToString();        //将num乘100并转换成字符串形式            j = str4.Length;      //找出最高位            if (j > 15){return "溢出";}            str2 = str2.Substring(15-j);   //取出对应位数的str2的值。如:200.55,j为5所以tr2=佰拾元角分                          //循环取出每一位需要转换的值            for(i=0;i<j;i++)            {                str3 = str4.Substring(i,1);          //取出需转换的某一位的值                temp = Convert.ToInt32(str3);      //转换为数字                if (i != (j-3) && i != (j-7) && i != (j-11) && i != (j-15))                {                        //当所取位数不为元、万、亿、万亿上的数字时                    if (str3 == "0")                    {                        ch1 = "";                        ch2 = "";                        nzero = nzero + 1;                    }                    else                    {                        if(str3 != "0" && nzero != 0)                        {                            ch1 = "零" + str1.Substring(temp*1,1);                            ch2 = str2.Substring(i,1);                            nzero = 0;                        }                        else                        {                            ch1 = str1.Substring(temp*1,1);                            ch2 = str2.Substring(i,1);                            nzero = 0;                        }                    }                }                else                {                      //该位是万亿,亿,万,元位等关键位                    if (str3 != "0" && nzero != 0)                    {                        ch1 = "零" + str1.Substring(temp*1,1);                        ch2 = str2.Substring(i,1);                        nzero = 0;                    }                    else                    {                        if (str3 != "0" && nzero == 0)                        {                            ch1 = str1.Substring(temp*1,1);                            ch2 = str2.Substring(i,1);                            nzero = 0;                        }                        else                        {                            if (str3 == "0" && nzero >= 3)                            {                                ch1 = "";                                ch2 = "";                                nzero = nzero + 1;                            }                            else                            {                                if (j >= 11)                                {                                    ch1 = "";                                    nzero = nzero + 1;                                }                                else                                {                                    ch1 = "";                                    ch2 = str2.Substring(i,1);                                    nzero = nzero + 1;                                }                            }                        }                    }                }                if (i == (j-11) || i == (j-3))                {                      //如果该位是亿位或元位,则必须写上                    ch2 = str2.Substring(i,1);                }                str5 = str5 + ch1 + ch2;                    if (i == j-1 && str3 == "0" )                {                        //最后一位(分)为0时,加上“整”                    str5 = str5 + '整';                }            }            if (num == 0)            {                str5 = "零元整";            }            return str5;        } 


[解决办法]

C# code
 public class ChinaMoney    {                private static string[] HanDigiStr = { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" };        private static string[] HanDiviStr = { "","拾","佰","仟","万","拾","佰","仟","亿",                                                  "拾","佰","仟","万","拾","佰","仟","亿",                                                  "拾","佰","仟","万","拾","佰","仟" };        private static string PositiveIntegerToHanStr(string NumStr)        {     // 输入字符串必须正整数,只允许前导空格(必须右对齐),不宜有前导零            string RMBStr = "";            int len, n;            bool hasvalue = false, lastzero = false;   // 亿、万进位前有数值标记            len = NumStr.Length;            for (int i = 0; i < len; i++)            {                //if( NumStr[i]==' ' ) continue;      // AnsiString[] base is 1                n = NumStr[i] - '0';                //if( n<0 || n>9 ) return "输入含非数字字符!";                int j = len - i - 1;                if (n != 0)                {                    if (lastzero) RMBStr += HanDigiStr[0];  // 若干零后若跟非零值,只显示一个零                    // 除了亿万前的零不带到后面                    //   if( !( n==1 && (i%4)==1 && (lastzero || i==len-1) ) )   // 如十进位前有零也不发壹音用此行                    //   if( !( n==1 && (i%4)==1 && i==len-1 ) )         // 十进位处于第一位不发壹音                    RMBStr += HanDigiStr[n];                    RMBStr += HanDiviStr[len - i - 1];   // 非零值后加进位,个位为空                    hasvalue = true;                                   // 置万进位前有值标记                }                else                {                    if (j == 8 || j == 4 && hasvalue)  // 亿万之间必须有非零值方显示万                        RMBStr += HanDiviStr[len - i - 1];  // “亿”或“万”                }                if (j % 8 == 0) hasvalue = false;     // 万进位前有值标记逢亿复位                lastzero = (n == 0) && (j % 4 != 0);                  // 亿万前有零后不加零,如:拾万贰仟            }            if (RMBStr.Length == 0) return HanDigiStr[0];         // 输入空字符或"0",返回"零"            return RMBStr;        }        /// <summary>        /// 金额转换大写        /// </summary>        /// <param name="val"></param>        /// <returns></returns>        public static string NumToRMBStr(double val)        {            if (val > 100000000000) return "数字过大!"; //不小于千亿(可以更大点但没有什么意义了)            string SignStr = "", TailStr = "";            double fraction = 0;            Int64 integer = 0;            if (val < 0)            {                val = -val;                SignStr = "负";            }            integer = Convert.ToInt64(val - val % 1); //整数部分 由于ToInt64本身有四舍五入功能所以要加 val%1 部分            int jiao, fen;            fraction = Math.Round(val % 1, 2); // 四舍五入到分 在.Net中四舍五入有点争议,它是伍不进位的。            fen = Convert.ToInt32((fraction * 100) % 10);//分            jiao = Convert.ToInt32((fraction * 100 - fen) / 10);//角            if (jiao == 0 && fen == 0)            {                TailStr = "整";            }            else            {                TailStr = HanDigiStr[jiao];                if (jiao != 0)                    TailStr += "角";                if (integer == 0 && jiao == 0)             // 零元后不写零几分                    TailStr = "";                if (fen != 0)                    TailStr += HanDigiStr[fen] + "分";            }            // 下一行可用于非正规金融场合,0.03只显示“叁分”而不是“零元叁分”            //        if( integer==0 ) return  SignStr+TailStr;            return SignStr + PositiveIntegerToHanStr(integer.ToString()) + "元" + TailStr;        }                    } 


[解决办法]

C# code
    public class XConvert  2    {  3        public static string ToRMB(Double e)  4        {  5            return ToRMB(System.Convert.ToDecimal(e));  6        }  7  8        public static string ToRMB(Decimal e)  9        { 10            string eString;//数字的格式化字符串 11            string eNum;//单数字 12            int eLen;//格式化字符串长度 13 14            System.Text.StringBuilder rmb=new System.Text.StringBuilder();//人民币大写 15            string yuan;//圆 16            bool seriesZero;//连续0标志 17            bool minus=false;//负数标志 18 19            if (e==0m) 20            { 21                return "零圆整"; 22            } 23            if (e<0m) 24            { 25                minus=true; 26                e=System.Math.Abs(e);                 27            } 28            if (e>999999999999.99m) 29            { 30                throw new Exception("超过最大范围"); 31            } 32 33            eString=e.ToString("0.00"); 34            eLen=eString.Length; 35            yuan=(eString.Substring(0,1)=="0"?"":"圆"); 36 37            eNum=eString.Substring(eLen-1,1);//分位 38            if (eNum=="0") 39            { 40                rmb.Append("整"); 41                seriesZero=true; 42            } 43            else 44            { 45                rmb.Append(stringNum(eNum)+"分"); 46                seriesZero=false; 47            } 48 49            eNum=eString.Substring(eLen-2,1);//角位 50            if (eNum=="0") 51            { 52                if (!seriesZero) 53                { 54                    if (!(eLen==4&&eString.Substring(0,1)=="0")) 55                    { 56                        rmb.Insert(0,"零"); 57                    } 58                } 59            } 60            else 61            { 62                rmb.Insert(0,stringNum(eNum)+"角");             63                seriesZero=false; 64            } 65 66            if (eLen<=7) 67            { 68                rmb.Insert(0,stringNum4(eString.Substring(0,eLen-3))+yuan); 69            } 70            else if (eLen<=11) 71            { 72                rmb.Insert(0,stringNum4(eString.Substring(eLen-7,4))+yuan); 73                rmb.Insert(0,stringNum4(eString.Substring(0,eLen-7))+"万"); 74            } 75            else if (eLen<=15) 76            { 77                rmb.Insert(0,stringNum4(eString.Substring(eLen-7,4))+yuan); 78                rmb.Insert(0,stringNum4(eString.Substring(eLen-11,4))+(eString.Substring(eLen-11,4)=="0000"?"":"万")); 79                rmb.Insert(0,stringNum4(eString.Substring(0,eLen-11))+"亿"); 80            } 81 82            if (minus) rmb.Insert(0,"负"); 83 84            return rmb.ToString(); 85        } 86 87        private static string stringNum4(string eNum4) 88        { 89            string eNum; 90            bool seriesZero=false; 91            System.Text.StringBuilder rmb4=new System.Text.StringBuilder(); 92            int eLen=eNum4.Length; 93 94            eNum=eNum4.Substring(eLen-1,1);//个位 95            if (eNum=="0") 96            { 97                seriesZero=true; 98            } 99            else100            {101                rmb4.Append(stringNum(eNum));102            }103104            if (eLen>=2)//十位105            {106                eNum=eNum4.Substring(eLen-2,1);107                if (eNum=="0")108                {109                    if (!seriesZero)110                    {111                        rmb4.Insert(0,"零");112                        seriesZero=true;113                    }114                }115                else116                {117                    rmb4.Insert(0,stringNum(eNum)+"拾");118                    seriesZero=false;119                }120            }121122            if (eLen>=3)//百位123            {124                eNum=eNum4.Substring(eLen-3,1);125                if(eNum=="0")126                {127                    if (!seriesZero)128                    {129                        rmb4.Insert(0,"零");130                        seriesZero=true;131                    }132                }133                else134                {135                    rmb4.Insert(0,stringNum(eNum)+"佰");136                    seriesZero=false;137                }138            }139140            if (eLen==4)//千位141            {142                eNum=eNum4.Substring(0,1);143                if(eNum=="0")144                {145                    if (!seriesZero)146                    {147                        rmb4.Insert(0,"零");148                        seriesZero=true;149                    }150                }151                else152                {153                    rmb4.Insert(0,stringNum(eNum)+"仟");154                    seriesZero=false;155                }156            }157158            return rmb4.ToString();159        }160161        private static string stringNum(string eNum)162        {163            switch (eNum)164            {165                case "1":166                    return "壹";167                case "2":168                    return "贰";169                case "3":170                    return "叁";171                case "4":172                    return "肆";173                case "5":174                    return "伍";175                case "6":176                    return "陆";177                case "7":178                    return "柒";179                case "8":180                    return "捌";181                case "9":182                    return "玖";183                default:184                    return "";185            }186        }187} 


[解决办法]
以前看到一vb的,家上有
[解决办法]
这么多代码……
[解决办法]
正解 学习中
[解决办法]
学习
[解决办法]
学习
[解决办法]

C# code
public static void Main()    {        Console.WriteLine(GetChinese(1230007890));    }    private static string digit = "零壹贰叁肆伍陆柒捌玖";    private static string quaterDom = "元万亿";    private static string Dom = "仟 拾佰";    private static string afterDom = "角分里";    public static string GetChinese(double value)    {        StringBuilder resultBuilder = new StringBuilder();        string[] doubleValue = value.ToString().Split(new char[] { '.' });        if (doubleValue.Length >= 1)        {                       for (int i = 0; i < doubleValue[0].Length; i++)            {                int decInt = doubleValue[0][i] - '0';                if (decInt != 0                     || (i < doubleValue[0].Length - 2 && doubleValue[0][i+1] != '0'                    && (doubleValue[0].Length - i) % 4 != 1))                {                    resultBuilder.Append(digit[decInt]);                    if (decInt != 0 && (doubleValue[0].Length - i) % 4 != 1)                        resultBuilder.Append(Dom[(doubleValue[0].Length - i) % 4]);                                    }                if ((doubleValue[0].Length - i) % 4 == 1)                    resultBuilder.Append(quaterDom[(doubleValue[0].Length - i) / 4]);            }        }        if (doubleValue.Length >= 2)        {            for (int i = 0; i < doubleValue[1].Length && i < afterDom.Length; i++)            {                int decInt = doubleValue[1][i] - '0';                if (decInt != 0                    || (i < doubleValue[0].Length - 2 && doubleValue[0][i + 1] != '0'))                {                    resultBuilder.Append(digit[decInt].ToString());                    if (decInt != 0)                        resultBuilder.Append(afterDom[i].ToString());                }            }        }        else            resultBuilder.Append("整");        return resultBuilder.ToString();    }
[解决办法]
帮顶
[解决办法]
学习
[解决办法]
希望能看到多一些的代码
[解决办法]
方法确实很多,LZ可以自己想个啊
[解决办法]
mark
[解决办法]
学习学习!!
[解决办法]
lg了,学习
[解决办法]
我写了个数据库层的方法供大家参考,是用一个自定义函数来解决的。
SQL code
if object_id('DaXie','FN') is not null 
drop function DaXie
go
/*=====================================
<Summary>:将数字金额转换为中文大写形式
<Author>:szx1999
<Create Date>:2009-05-05
=====================================*/
create function DaXie(@s nvarchar(40))
returns nvarchar(100)


as
begin
--构建单位表
declare @t table(id int identity(1,1),ch nvarchar(5))
insert @t select '拾' union all select '佰' union all select '仟' union all select '万'
union all select '拾' union all select '佰' union all select '仟' union all select '亿' union all select '拾'
union all select '佰' union all select '仟' union all select '万' union all select '拾万' union all select '佰万'
union all select '仟万' union all select '亿'
--将数字转为大写
set @s=replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(@s,'0','零')
,'1','壹'),'2','贰'),'3','叁'),'4','肆'),'5','伍'),'6','陆'),'7','柒'),'8','捌'),'9','玖')
--划分为整数和小数两部分
declare @s1 nvarchar(30),@s2 nvarchar(10),@sLen int
if charindex('.',@s)>0
select @s1=left(@s,len(@s)-3),@s2='元'+stuff(right(@s,2),2,0,'角')+'分'
else
select @s1=@s,@s2='元整'
--把整数部分加上单位
set @sLen=len(@s1)
select @s1=case when id in (4,8,12,16) and substring(@s1,@sLen-id,1)='零' then stuff(@s1,@sLen-id,1,ch) else stuff(@s1,@sLen-id+1,0,ch) end
from @t where id <@sLen and (substring(@s1,@sLen-id,1) <>'零' or id in (4,8,12,16))
--去除多余的零,以符合阅读习惯
while patindex('%零[^壹贰叁肆伍陆柒捌玖]%',@s1)>0
set @s1=stuff(@s1,patindex('%零[^壹贰叁肆伍陆柒捌玖]%',@s1),1,'')

return @s1+@s2
end
go

--使用示例:
select dbo.DaXie('12300078.48')
/*
-------------------------------------
壹仟贰佰叁拾万零柒拾捌元肆角捌分

(1 行受影响)
*/

select dbo.DaXie('123456009123')
/*
-------------------------------------
壹仟贰佰叁拾肆亿伍仟陆佰万玖仟壹佰贰拾叁元整

(1 行受影响)
*/


[解决办法]
参数检查部分忽略没写。
[解决办法]
C# code
using System;using System.Text.RegularExpressions;using System.Text;namespace test  /////////////////{               ////////////////                /// <summary>///                //                /// </summary>///                /////////////////    class Program    {   /**  16409.02 壹万陆仟肆佰零玖元零贰分  **/        static void Main(string[] args)        {            string money = "10056.56";            StringBuilder sb = new StringBuilder();            //Console.WriteLine(Regex.IsMatch(money, "^0\\.\\d{1,2}$"));            Regex rxInput = new Regex("^(?(?=0)0|[1-9]\\d*)(?(?=\\.)\\.\\d{1,2}|)$");            if (rxInput.IsMatch(money))            {                Console.WriteLine("------输入正确------");                Console.WriteLine(money);                if (!Regex.IsMatch(money, "\\."))                {                    money = money + ".00";                }                else if (Regex.IsMatch(money, "^.+\\.\\d{1}$"))                {                    money = money + "0";                }                int j = 0;                if (Regex.IsMatch(money, "\\.\\d{2}"))                {                    for (int i = money.Length - 1; i >= 0; i--)                    {                        sb.Append(Convert1(money[j++]));//转成汉字                        sb.Append(Convert2(i));//单位                    }                    string temp = sb.ToString();//书面写                    Console.WriteLine(temp);                    //"[零.&&[^零元]]"不能用。。                    temp = Regex.Replace(temp, "零(?=(元|万|亿))", "");                    temp = Regex.Replace(temp, "零(仟|佰|拾)", "零");                    temp = Regex.Replace(temp, "零{2,3}", "零");                    temp = Regex.Replace(temp, "零(?=(元|万|亿))", "");                    temp = Regex.Replace(temp, "亿万", 


[解决办法]
收藏!
[解决办法]
学习学习学习,以前我也看过这样的,但是也忘了,貌似没那么复杂
[解决办法]
哇好牛,学习了
[解决办法]
public static string DoNumberCurrencyToChineseCurrency(string str)
{
if (str.Length < 1)
{
return string.Empty;
}
str = str.Replace(",", string.Empty);
str = str.Replace(",", string.Empty);
str = str.Replace("。", ".");
str = str.Replace("-", string.Empty);
str = str.Replace("+", string.Empty);
str = str.Replace("元", string.Empty);

System.Text.RegularExpressions.Regex reg1 = new System.Text.RegularExpressions.Regex(@"^[-]?\d+[.]?\d*$");
if (!reg1.IsMatch(str))
{
return string.Empty;
}

string[] cstr ={ "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" };
string[] wstr ={ "", "", "拾", "佰", "仟", "万", "拾", "佰", "仟", "亿", "拾", "佰", "仟" };

while (str.StartsWith("0"))
{
str = str.Substring(1, str.Length - 1);
}
string strInt = str;
string strDec = string.Empty;
string ReturnDec = string.Empty;
int Index = str.IndexOf(".");
if (Index > 0)
{ strInt = str.Substring(0, Index);
strDec = str.Substring(Index + 1);
string[] fsstr = new string[] { "角", "分" };
for (int a = 0; a < 2; a++)
{
ReturnDec = ReturnDec + cstr[int.Parse(strDec[a].ToString())] + fsstr[a];
}
}
int len = strInt.Length;
int i;
string tmpstr, rstr;
rstr = "";
for (i = 1; i <= len; i++)
{
tmpstr = strInt.Substring(len - i, 1);
rstr = string.Concat(cstr[Int32.Parse(tmpstr)] + wstr[i], rstr);
}
rstr = rstr.Replace("拾零", "拾");
rstr = rstr.Replace("零拾", "零");
rstr = rstr.Replace("零佰", "零");
rstr = rstr.Replace("零仟", "零");
rstr = rstr.Replace("零万", "万");
for (i = 1; i <= 6; i++)
rstr = rstr.Replace("零零", "零");
rstr = rstr.Replace("零万", "零");
rstr = rstr.Replace("零亿", "亿");
rstr = rstr.Replace("零零", "零");
rstr += "元";

if (ReturnDec.Length > 0)
{
rstr = rstr + ReturnDec;
}
else
{
rstr += "整";
}
return rstr;
}
参考
[解决办法]
参考
参考
[解决办法]
学习了,帮顶下。


[解决办法]
mark
[解决办法]
好多方法
[解决办法]
上面的都不错,呵呵。你选一个简单的就行了。
[解决办法]
天...我逻辑有问题了...得睡了
[解决办法]
[code=C#]
1 public class XConvert
2 {
3 public static string ToRMB(Double e)
4 {
5 return ToRMB(System.Convert.ToDecimal(e));
6 }
7
8 public static string ToRMB(Decimal e)
9 {
10 string eString;//数字的格式化字符串
11 string eNum;//单数字
12 int eLen;//格式化字符串长度
13
14 System.Text.StringBuilder rmb=new System.Text.StringBuilder();//人民币大写
15 string yuan;//圆
16 bool seriesZero;//连续0标志
17 bool minus=false;//负数标志
18
19 if (e==0m)
20 {
21 return "零圆整";
22 }
23 if (e<0m)
24 {
25 minus=true;
26 e=System.Math.Abs(e);
27 }
28 if (e>999999999999.99m)
29 {
30 throw new Exception("超过最大范围");
31 }
32
33 eString=e.ToString("0.00");
34 eLen=eString.Length;
35 yuan=(eString.Substring(0,1)=="0"?"":"圆");
36
37 eNum=eString.Substring(eLen-1,1);//分位
38 if (eNum=="0")
39 {
40 rmb.Append("整");
41 seriesZero=true;
42 }
43 else
44 {
45 rmb.Append(stringNum(eNum)+"分");
46 seriesZero=false;
47 }
48
49 eNum=eString.Substring(eLen-2,1);//角位
50 if (eNum=="0")
51 {
52 if (!seriesZero)
53 {
54 if (!(eLen==4&&eString.Substring(0,1)=="0"))
55 {
56 rmb.Insert(0,"零");
57 }
58 }
59 }
60 else
61 {
62 rmb.Insert(0,stringNum(eNum)+"角");
63 seriesZero=false;
64 }
65
66 if (eLen<=7)
67 {
68 rmb.Insert(0,stringNum4(eString.Substring(0,eLen-3))+yuan);
69 }
70 else if (eLen<=11)
71 {
72 rmb.Insert(0,stringNum4(eString.Substring(eLen-7,4))+yuan);
73 rmb.Insert(0,stringNum4(eString.Substring(0,eLen-7))+"万");
74 }
75 else if (eLen<=15)
76 {
77 rmb.Insert(0,stringNum4(eString.Substring(eLen-7,4))+yuan);
78 rmb.Insert(0,stringNum4(eString.Substring(eLen-11,4))+(eString.Substring(eLen-11,4)=="0000"?"":"万"));


79 rmb.Insert(0,stringNum4(eString.Substring(0,eLen-11))+"亿");
80 }
81
82 if (minus) rmb.Insert(0,"负");
83
84 return rmb.ToString();
85 }
86
87 private static string stringNum4(string eNum4)
88 {
89 string eNum;
90 bool seriesZero=false;
91 System.Text.StringBuilder rmb4=new System.Text.StringBuilder();
92 int eLen=eNum4.Length;
93
94 eNum=eNum4.Substring(eLen-1,1);//个位
95 if (eNum=="0")
96 {
97 seriesZero=true;
98 }
99 else
100 {
101 rmb4.Append(stringNum(eNum));
102 }
103
104 if (eLen>=2)//十位
105 {
106 eNum=eNum4.Substring(eLen-2,1);
107 if (eNum=="0")
108 {
109 if (!seriesZero)
110 {
111 rmb4.Insert(0,"零");
112 seriesZero=true;
113 }
114 }
115 else
116 {
117 rmb4.Insert(0,stringNum(eNum)+"拾");
118 seriesZero=false;
119 }
120 }
121
122 if (eLen>=3)//百位
123 {
124 eNum=eNum4.Substring(eLen-3,1);
125 if(eNum=="0")
126 {
127 if (!seriesZero)
128 {
129 rmb4.Insert(0,"零");
130 seriesZero=true;
131 }
132 }
133 else
134 {
135 rmb4.Insert(0,stringNum(eNum)+"佰");
136 seriesZero=false;
137 }
138 }
139
140 if (eLen==4)//千位
141 {
142 eNum=eNum4.Substring(0,1);
143 if(eNum=="0")
144 {
145 if (!seriesZero)
146 {
147 rmb4.Insert(0,"零");
148 seriesZero=true;
149 }
150 }
151 else
152 {
153 rmb4.Insert(0,stringNum(eNum)+"仟");
154 seriesZero=false;
155 }
156 }
157
158 return rmb4.ToString();
159 }
160
161 private static string stringNum(string eNum)
162 {
163 switch (eNum)
164 {
165 case "1":
166 return "壹";
167 case "2":
168 return "贰";
169 case "3":
170 return "叁";
171 case "4":
172 return "肆";
173 case "5":
174 return "伍";
175 case "6":
176 return "陆";
177 case "7":
178 return "柒";
179 case "8":
180 return "捌";
181 case "9":
182 return "玖";
183 default:
184 return "";


185 }
186 }
187[code]
[解决办法]
发现一个叫 礼拜一 的家伙,汗~
[解决办法]
接分。
[解决办法]

探讨
C# codepublic static string CmycurD(decimal num)
{
string str1 = "零壹贰叁肆伍陆柒捌玖"; //0-9所对应的汉字
string str2 = "万仟佰拾亿仟佰拾万仟佰拾元角分"; //数字位所对应的汉字
string str3 = ""; //从原num值中取出的值
string str4 = ""; //数字的字符串形式
string str5 = ""; //人民币大写金额形式
i…

[解决办法]
绝对顶。
[解决办法]
见识了 都是高手啊
[解决办法]
mark
[解决办法]
帮顶
[解决办法]
怎一个强字了得
[解决办法]
关注
[解决办法]
C# code
  public string ConvertSum(string str)    {        if (!IsPositveDecimal(str))            return "输入的不是正数字!";        if (Double.P * **(str) > 999999999999.99)            return "数字太大,无法换算,请输入一万亿元以下的金额";        char[] ch = new char[1];        ch[0] = '.'; //小数点         string[] splitstr = null; //定义按小数点分割后的字符串数组         splitstr = str.Split(ch[0]);//按小数点分割字符串         if (splitstr.Length == 1) //只有整数部分             return ConvertData(str) + "圆整";        else //有小数部分         {            string rstr;            rstr = ConvertData(splitstr[0]) + "圆";//转换整数部分             rstr += ConvertXiaoShu(splitstr[1]);//转换小数部分             return rstr;        }    }    /// <summary>     /// 判断是否是正数字字符串     /// </summary>     /// <param name="str"> 判断字符串</param>     /// <returns>如果是数字,返回true,否则返回false</returns>     public bool IsPositveDecimal(string str)    {        Decimal d;        try        {            d = Decimal.P * **(str);        }        catch (Exception)        {            return false;        }        if (d > 0)            return true;        else            return false;    }    /// <summary>     /// 转换数字(整数)     /// </summary>     /// <param name="str">需要转换的整数数字字符串</param>     /// <returns>转换成中文大写后的字符串</returns>     public string ConvertData(string str)    {        string tmpstr = "";        string rstr = "";        int strlen = str.Length;        if (strlen <= 4)//数字长度小于四位         {            rstr = ConvertDigit(str);        }        else        {            if (strlen <= 8)//数字长度大于四位,小于八位             {                tmpstr = str.Substring(strlen - 4, 4);//先截取最后四位数字                 rstr = ConvertDigit(tmpstr);//转换最后四位数字                 tmpstr = str.Substring(0, strlen - 4);//截取其余数字                 //将两次转换的数字加上后相连接                 rstr = String.Concat(ConvertDigit(tmpstr) + "", rstr);                rstr = rstr.Replace("零", "");                rstr = rstr.Replace("零零", "零");            }            else                if (strlen <= 12)//数字长度大于八位,小于十二位                 {                    tmpstr = str.Substring(strlen - 4, 4);//先截取最后四位数字                     rstr = ConvertDigit(tmpstr);//转换最后四位数字                     tmpstr = str.Substring(strlen - 8, 4);//再截取四位数字                     rstr = String.Concat(ConvertDigit(tmpstr) + "", rstr);                    tmpstr = str.Substring(0, strlen - 8);                    rstr = String.Concat(ConvertDigit(tmpstr) + "", rstr);                    rstr = rstr.Replace("零", "");                    rstr = rstr.Replace("零", "零");                    rstr = rstr.Replace("零零", "零");                    rstr = rstr.Replace("零零", "零");                }        }        strlen = rstr.Length;        if (strlen >= 2)        {            switch (rstr.Substring(strlen - 2, 2))            {                case "佰零": rstr = rstr.Substring(0, strlen - 2) + "佰"; break;                case "仟零": rstr = rstr.Substring(0, strlen - 2) + "仟"; break;                case "零": rstr = rstr.Substring(0, strlen - 2) + ""; break;                case "零": rstr = rstr.Substring(0, strlen - 2) + ""; break;            }        }        return rstr;    }    /// <summary>     /// 转换数字(小数部分)     /// </summary>     /// <param name="str">需要转换的小数部分数字字符串</param>     /// <returns>转换成中文大写后的字符串</returns>     public string ConvertXiaoShu(string str)    {        int strlen = str.Length;        string rstr;        if (strlen == 1)        {            rstr = ConvertChinese(str) + "角";            return rstr;        }        else        {            string tmpstr = str.Substring(0, 1);            rstr = ConvertChinese(tmpstr) + "角";            tmpstr = str.Substring(1, 1);            rstr += ConvertChinese(tmpstr) + "分";            rstr = rstr.Replace("零分", "");            rstr = rstr.Replace("零角", "");            return rstr;        }    }    /// <summary>     /// 转换数字     /// </summary>     /// <param name="str">转换的字符串(四位以内)</param>     /// <returns></returns>     public string ConvertDigit(string str)    {        int strlen = str.Length;        string rstr = "";        switch (strlen)        {            case 1: rstr = ConvertChinese(str); break;            case 2: rstr = Convert2Digit(str); break;            case 3: rstr = Convert3Digit(str); break;            case 4: rstr = Convert4Digit(str); break;        }        rstr = rstr.Replace("拾零", "拾");        strlen = rstr.Length;        return rstr;    }    /// <summary>     /// 转换四位数字     /// </summary>     public string Convert4Digit(string str)    {        string str1 = str.Substring(0, 1);        string str2 = str.Substring(1, 1);        string str3 = str.Substring(2, 1);        string str4 = str.Substring(3, 1);        string rstring = "";        rstring += ConvertChinese(str1) + "仟";        rstring += ConvertChinese(str2) + "佰";        rstring += ConvertChinese(str3) + "拾";        rstring += ConvertChinese(str4);        rstring = rstring.Replace("零仟", "零");        rstring = rstring.Replace("零佰", "零");        rstring = rstring.Replace("零拾", "零");        rstring = rstring.Replace("零零", "零");        rstring = rstring.Replace("零零", "零");        rstring = rstring.Replace("零零", "零");        return rstring;    }    /// <summary>     /// 转换三位数字     /// </summary>     public string Convert3Digit(string str)    {        string str1 = str.Substring(0, 1);        string str2 = str.Substring(1, 1);        string str3 = str.Substring(2, 1);        string rstring = "";        rstring += ConvertChinese(str1) + "佰";        rstring += ConvertChinese(str2) + "拾";        rstring += ConvertChinese(str3);        rstring = rstring.Replace("零佰", "零");        rstring = rstring.Replace("零拾", "零");        rstring = rstring.Replace("零零", "零");        rstring = rstring.Replace("零零", "零");        return rstring;    }    /// <summary>     /// 转换二位数字     /// </summary>     public string Convert2Digit(string str)    {        string str1 = str.Substring(0, 1);        string str2 = str.Substring(1, 1);        string rstring = "";        rstring += ConvertChinese(str1) + "拾";        rstring += ConvertChinese(str2);        rstring = rstring.Replace("零拾", "零");        rstring = rstring.Replace("零零", "零");        return rstring;    }    /// <summary>     /// 将一位数字转换成中文大写数字     /// </summary>     public string ConvertChinese(string str)    {        //"零壹贰叁肆伍陆柒捌玖拾佰仟圆整角分"         string cstr = "";        switch (str)        {            case "0": cstr = "零"; break;            case "1": cstr = "壹"; break;            case "2": cstr = "贰"; break;            case "3": cstr = "叁"; break;            case "4": cstr = "肆"; break;            case "5": cstr = "伍"; break;            case "6": cstr = "陆"; break;            case "7": cstr = "柒"; break;            case "8": cstr = "捌"; break;            case "9": cstr = "玖"; break;        }        return (cstr);    } 


[解决办法]
有意思。。。
[解决办法]
标记。期待更精简的。
[解决办法]

探讨
是不是最简单的解法?

C# code static void Main(string[] args)
{
Console.WriteLine(GetChinese(123120003.345));
}

private static string digit = "零壹贰叁肆伍陆柒捌玖";
private static string Dom = "仟佰拾万仟佰拾亿仟佰拾万仟佰拾元角分里";

public static string GetChinese(double value)
{
string value…

读书人网 >C#

热点推荐