编了一个简单的把阿拉伯数字转化成中文表示的程序,很粗糙,欢迎大家优化!!!

      /// <summary>
      /// 函数名称:NumToChn
      /// 功能描述:将数字格式化成中文表示法
      /// </summary>
      /// <param name="nNum">待格式化的数字</param>
      /// <param name="bJz">是否使用进位字</param>
      /// <returns>已格式化的时间</returns>
      static public string NumToChn(int nNum,bool bJz)      //算法不好,只能上千万,以后最好改为递归实现
      {
         string [] strNumber={"〇","一","二","三","四","五","六","七","八","九"};
         string [] strJz={"","十","百","千","万"};
         string strReturn="";
         string strTmp="";
         int i=0;
         bool bZero=false;
         int m;

         do
         {
            m=nNum%10;
            nNum/=10;
            strTmp=strNumber[m];
            if (bJz)    //使用进位字
            {
               if (m>0)
               {
                  if (i==1&&m==1)
                     strTmp=strJz[i];
                  else
                  {
                     strTmp+=strJz[i];
                     if (bZero)
                        strTmp+=strNumber[0];
                     bZero=false;
                  }
               }
               else
               {
                  if (i<1)
                     strTmp=strJz[i];
                  else
                  {
                     strTmp="";
                     bZero=true;
                  }
               }
               if (++i>3)
               {
                  i=0;
                  strTmp="万"+strTmp;
               }
            }
            strReturn=strTmp+strReturn;
         }while (nNum>0);
         return strReturn;
      }

posted @ 2005-01-21 16:34  lykyl的自留地  阅读(1005)  评论(4编辑  收藏  举报