注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

意寓云天的博客

平静的湖面只有呆板的倒影,奔腾的激流才有美丽的浪花!

 
 
 

日志

 
 

从小数转换成中文金额大写,C#  

2007-08-02 11:11:57|  分类: 硬件技术 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
#region 新大写转换函数 private static char ToNum(char x)
        {
           
string strChnNames="零壹贰叁肆伍陆柒捌玖";
           
string strNumNames="0123456789";
           
return strChnNames[strNumNames.IndexOf(x)];
        }
 
       
// 转换万以下整数
        private static string ChangeInt(string x)
        {
           
string[] strArrayLevelNames=new string[4] {"","","",""};
           
string ret = "";
           
int i;
           
for (i=x.Length-1;i>=0;i--)
               
if (x[i] == '0')
                    ret
= ToNum(x[i]) + ret;
               
else
                    ret
= ToNum(x[i]) + strArrayLevelNames[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 static string ToInt(string x)
        {
           
int len = x.Length;
           
string ret,temp;
           
if (len<=4)
                ret
= ChangeInt(x);
           
else if (len<=8)
            {
                ret
= ChangeInt(x.Substring(0,len-4)) + "";
                temp
= ChangeInt(x.Substring(len-4,4));
               
if (temp.IndexOf("")==-1 && temp!="")
                    ret
+= "" + temp;
               
else
                    ret
+= temp;
            }
           
else
            {
                ret
=ChangeInt(x.Substring(0,len-8)) + "亿";
                temp
=ChangeInt(x.Substring(len-8,4));
               
if (temp.IndexOf("")==-1 && temp!="")
                    ret
+= "" + temp;
               
else
                    ret
+= temp;
                ret
+= "";
                temp
= ChangeInt(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 static string ToDecimal(string x)
        {
           
string ret = "";
           
int i = 0;
           
if (x != "00")
            {
               
if (x.Substring(0,1) != "0")
                {
                    i
= x[0] - 48; //Ascii
                    ret = ToNum(i.ToString()[0]) + "" + ret;
                }
               
else
                    ret
= ToNum(i.ToString()[0]) + ret;

               
if (x.Substring(1,1) != "0")
                {
                    i
= x[1] - 48; //Ascii
                    ret = ret + ToNum(i.ToString()[0]) + "";
                }
            }
           
else
            {
                ret
= "";
            }
           
return ret;
        }

       
public static string MoneyLowerToUpper(decimal rmb)
        {
           
string x = rmb.ToString();
           
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
+= ToInt(x.Substring(0,x.IndexOf(".")))+""+ToDecimal(x.Substring(x.IndexOf(".")+1));
           
else
                ret
+= ToInt(x);
           
return ret;
        }

       
#endregion
  评论这张
 
阅读(186)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017