• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C#实现小写金额转大写金额

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

最近项目上用到小写转大写金额,公司同事还准备写一段代码来实现,后来发现架构上有现成的。

 

其实在银行、进销存、CRM等系统中经常可能用到

  这个跟大家分享一下:

 

 

小写金额转大写
/// <summary>
        
///        获取金额的大写中文文字            返回:中文数字文字
        //        mvarOrDollar 数字金额大小, mstrLanguage 字符串语言 P:简体中文 C:繁体中文  
        /// </summary>
        
/// <param name="mvarOrDollar"></param>
        
/// <param name="mstrLanguage"></param>
        
/// <returns></returns>
        public static string GetDollorStr(double mvarOrDollar)
        {
            
//返回简体中文的中文描述
            return GetDollorStr(mvarOrDollar,"P");
        }
        
public static string GetDollorStr(double mvarOrDollar,string mstrLanguage)
        {
            
string t_word;
            
string WLAMT;
            
//            double tt;
            t_word = "";
            
//            If mstrLanguage = "E" Or mstrLanguage = "e" Then
            
//                t_word = t_word + noinword(Int(mvarOrDollar))
            
//                If mvarOrDollar <> Int(mvarOrDollar) Then
            
//                    tt = Int((mvarOrDollar - Int(mvarOrDollar)) * 100)
            
//                    t_word = t_word & "And " & " Cents " & noinword(tt)
            
//                End If
            
//                 
            
//            Else
            
//            WLAMT = mvarOrDollar.ToString();
            WLAMT = StrFormat(mvarOrDollar, 122);
            
            
for(int i = 0;i<12;i++)
            {                       
                
if (i != 9)
                    t_word 
= t_word + SHRCHG(WLAMT, WLAMT.Substring(i, 1), i, mstrLanguage);
                 
            }
            
string spacestr = "";
            t_word 
= t_word + spacestr.PadLeft(40 - t_word.Length,' ');
                
            
//            End If
            return t_word.Trim();
        }

        
private static string SHRCHG(string WLAMT, string WLCD,int WLLOC,string mstrLanguage)
        {
            
string WLNAME;
            
string WLDD;
            
if (mstrLanguage == "C"
                WLDD 
= "货ㄕ珺窾ㄕ珺じ  àだ";
            
else
                
//WLDD = "亿千百十万千百十元 角分";
                WLDD = "亿仟佰拾万仟佰拾元 角分";
 
            WLNAME 
= "    ";
            
switch (WLCD)
            {
                
case " ":
                    WLNAME 
= "   ";
                    
break;
                
case "1":
                    
//WLNAME = IIf(mstrLanguage = "C", "滁", "壹") + Mid(WLDD, (WLLOC - 1) * 2 + 1, 2)
                    if(mstrLanguage.Equals("C"))
                        WLNAME 
= ""  + WLDD.Substring(WLLOC, 1);
                    
else
                        WLNAME 
= "" + WLDD.Substring(WLLOC, 1);
                    
break;
                
case "2":
                    
//'WLNAME = IIf(mstrLanguage = "C", "禠", "贰") + Mid(WLDD, (WLLOC - 1) * 2 + 1, 2)
                    if(mstrLanguage.Equals("C"))
                        WLNAME 
= ""  + WLDD.Substring(WLLOC, 1);
                    
else
                        WLNAME 
= "" + WLDD.Substring(WLLOC, 1);
                                        
                    
break;
                
case "3":
                    
//'WLNAME = IIf(mstrLanguage = "C", "把", "叁") + Mid(WLDD, (WLLOC - 1) * 2 + 1, 2)
                    if(mstrLanguage.Equals("C"))
                        WLNAME 
= ""  + WLDD.Substring(WLLOC, 1);
                    
else
                        WLNAME 
= "" + WLDD.Substring(WLLOC, 1);
                    
                    
break;
                
case "4":
                    
//'WLNAME = IIf(mstrLanguage = "C", "竩", "肆") + Mid(WLDD, (WLLOC - 1) * 2 + 1, 2)
                    if(mstrLanguage.Equals("C"))
                        WLNAME 
= ""  + WLDD.Substring(WLLOC, 1);
                    
else
                        WLNAME 
= "" + WLDD.Substring(WLLOC, 1);
                    
                    
break;
                
case "5":
                    
//'WLNAME = IIf(mstrLanguage = "C", "ヮ", "伍") + Mid(WLDD, (WLLOC - 1) * 2 + 1, 2)
                    if(mstrLanguage.Equals("C"))
                        WLNAME 
= ""  + WLDD.Substring(WLLOC, 1);
                    
else
                        WLNAME 
= "" + WLDD.Substring(WLLOC, 1);
                    
                    
break;
                
case "6":
                    
//'WLNAME = IIf(mstrLanguage = "C", "嘲", "陆") + Mid(WLDD, (WLLOC - 1) * 2 + 1, 2)
                    if(mstrLanguage.Equals("C"))
                        WLNAME 
= ""  + WLDD.Substring(WLLOC, 1);
                    
else
                        WLNAME 
= "" + WLDD.Substring(WLLOC, 1);
                    
                    
break;
                
case "7":
                    
//'WLNAME = IIf(mstrLanguage = "C", "琺", "柒") + Mid(WLDD, (WLLOC - 1) * 2 + 1, 2)
                    if(mstrLanguage.Equals("C"))
                        WLNAME 
= ""  + WLDD.Substring(WLLOC, 1);
                    
else
                        WLNAME 
= "" + WLDD.Substring(WLLOC, 1);
                    
                    
break;
                
case "8":
                    
//'WLNAME = IIf(mstrLanguage = "C", "", "捌") + Mid(WLDD, (WLLOC - 1) * 2 + 1, 2)
                    if(mstrLanguage.Equals("C"))
                        WLNAME 
= ""  + WLDD.Substring(WLLOC, 1);
                    
else
                        WLNAME 
= "" + WLDD.Substring(WLLOC, 1);
                    
break;
                
case "9":
                    
//'WLNAME = IIf(mstrLanguage = "C", "╤", "玖") + Mid(WLDD, (WLLOC - 1) * 2 + 1, 2)
                    if(mstrLanguage.Equals("C"))
                        WLNAME 
= ""  + WLDD.Substring(WLLOC, 1);
                    
else
                        WLNAME 
= "" + WLDD.Substring(WLLOC, 1);
                    
break;
                
case "0":
                    
string locList = "123567";
                    
if (locList.IndexOf(WLLOC.ToString().Trim()) > 0 && WLAMT.Substring(WLLOC + 11!= "0")
                        
if(mstrLanguage.Equals("C"))
                            WLNAME 
= "";
                        
else
                            WLNAME 
= "";
                    
else
                        WLNAME 
= "";
                    
if (WLAMT.Substring(WLLOC,1== ".")
                        WLNAME 
= WLDD.Substring(WLLOC, 1);
                    
                    
if (WLLOC == 4 && (WLAMT.Substring(11!= "0" || WLAMT.Substring(21!= "0" || WLAMT.Substring(31!= "0"))
                        
if(mstrLanguage.Equals("C"))
                            WLNAME 
= "";
                        
else
                            WLNAME 
= "";
                    
break;
                                                                
            }                                                                                                                                                                                                                                                  
            
return WLNAME.Trim();
        }

        
private static string StrFormat(double Tlong,int Along,int Adec)
        {
            
string tstr;
   
   
            tstr 
= Tlong.ToString().Trim();
            
if (tstr.IndexOf("."== -1)
            {
                tstr 
+= ".00";
            }
            
else
            {
                
if (tstr.IndexOf("."== 0)
                {
                    tstr 
= "0" + tstr;
                }
                
if (tstr.IndexOf("."== tstr.Length - 1)  //0.  case
                {
                    tstr 
= tstr + "0";
                }
                
if (tstr.Substring(tstr.IndexOf("."+ 1).Length == 1)
                {
                    tstr 
= tstr + "0";
                }
                
else
                {
                    tstr 
= tstr.Substring(0, tstr.IndexOf("."+ 3);
                }
                
            }    
            
if (tstr.Length < 12
                tstr 
= tstr.PadLeft(12,' ');
            
return tstr;

        }

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
c#下载并保存文件在程序目录发布时间:2022-07-10
下一篇:
C#創建彈出式菜單(ToolStripMenuItem发布时间:2022-07-10
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap