ERP GPS Web Asp.net Javascipt

梦想璀璨

VB TSQL C# Javascript asp.net

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
public static string Money2Chinese(double value)
        {
   string sValue = String.Format("{0:F2}",value);
   int point = sValue.IndexOf('.');
   char[] chValues1 = sValue.Substring(0,point).ToCharArray();
   char[] chValues2 = sValue.Substring(point+1,2).ToCharArray();
            char[] chHan = new char[] { '零', '壹', '贰', '叁', '肆', '伍', '陆', '柒','捌', '玖' };
   char[] powers = new char[] {'万','仟','佰','拾','亿','仟','佰','拾','万','仟','佰','拾','元'};
            int MaxPower = chValues1.Length;
            int PowerLen = powers.Length;
            if(MaxPower > PowerLen) return "超出范围";
            int digital;
            int j;
            string ch="",strTmp = "";        
            Stack<string> tmp = new Stack<string>();           
           
            if(value==0.0)
            {
             return "零元整";
            }
            if(value < 1.0)
            {
             if(chValues2[0] != '0')
             {
              digital=Convert.ToInt32(chValues2[0].ToString());
              ch = chHan[digital].ToString() + "角";
              tmp.Push(ch);
             }            
             if(chValues2[1] != '0')
             {
              digital=Convert.ToInt32(chValues2[1].ToString());
              ch = chHan[digital].ToString() + "分";
              tmp.Push(ch);
             }
             else
             {
              tmp.Push("整");
             }
            }
            else
            {
             for (int i=0 ; i < MaxPower ;i++)
             {
              j = i + (PowerLen - MaxPower);
              if(chValues1[i]=='0')
              {              
               if(tmp.Peek()=="零")
               {
                ch = powers[j].ToString();
                if(ch=="亿" || ch=="万")
                   {
                    tmp.Pop();       
                    if(tmp.Count > 0)
                    {
                     strTmp=tmp.Peek();
                     strTmp=strTmp[strTmp.Length-1].ToString();
                     if(strTmp!="亿")
                      tmp.Push(ch);                     
                    }
                    tmp.Push("零");
                   }
                else if( ch == "元" )
                {
                 tmp.Pop();
                 tmp.Push("元");
                }
               }
               else
               {               
                ch = powers[j].ToString();
                   if(ch=="亿" || ch=="万" || ch == "元" )
                   {
                    tmp.Push(ch);
                    if(ch!="元")
                     tmp.Push("零");
                   }
                   else
                   {
                    tmp.Push("零");
                   }
               }
              }
              else
              {
               digital = Convert.ToInt32(chValues1[i].ToString());
                  ch = chHan[digital].ToString() + powers[j].ToString();
                  tmp.Push(ch);
              }
             }
             /*
             if(chValues1[point-1]=='0')
             {
              if(chValues2[0] != '0' || chValues2[1] != '0')
              {               
               tmp.Push("零");
              }
             }
             */
             if(chValues2[0] != '0')
             {
              digital=Convert.ToInt32(chValues2[0].ToString());
              ch = chHan[digital].ToString() + "角";
              tmp.Push(ch);              
             }
             else if(chValues2[1]!='0')
             {
              ch=tmp.Peek();
              if(ch!="零")
               tmp.Push("零");
             }
             if(chValues2[1] != '0')
             {
              digital=Convert.ToInt32(chValues2[1].ToString());
              ch = chHan[digital].ToString() + "分";
              tmp.Push(ch);
             }
             else
             {
              tmp.Push("整");
             }
            }
           
            StringBuilder sb= new StringBuilder();
            string[] strArray = tmp.ToArray();
            for(int i = strArray.Length-1 ; i >=0; i -- )
            {
             sb.Append(strArray[i]);
            }
            return sb.ToString();
        }
posted on 2007-07-19 15:58  忙碌de代码  阅读(217)  评论(0编辑  收藏  举报
CopyRight:jetmeng 2008-2010