C#轉換英文大寫(兩位小數)

來源:互聯網
上載者:User

 string[] arr1 = new string[4] {"", " THOUSAND", " MILLION", " BILLION"};
    string[] arr2 = new string[10] {"ZERO", "TEN", "TWENTY", "THIRTY", "FORTY", "FIFTY", "SIXTY", "SEVENTY", "EIGHTY", "NINETY"};
    string[] arr3 = new string[10] {"ZERO", "ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN", "EIGHT", "NINE"};
    string[] arr4 = new string[10] { "TEN", "ELEVEN", "TWELVE", "THIRTEEN", "FOURTEEN", "FIFTEEN", "SIXTEEN", "SEVENTEEN", "EIGHTEEN", "NINETEEN" };

# region 英文數字翻譯
    private  string  Translate(string  num)
    {
       
         double  len=num.Length;
         int  i,j=0;
         string  strRet="";
         double  cols1=Math.Ceiling(len/3);
         int cols = SysConvert.ToInt32(cols1);
         double    first1=len-cols1*3;
         int first = SysConvert.ToInt32(first1);

         for(i=SysConvert.ToInt32( first);i<len;i+=3)
         {
             string num3 = "";
                     ++j;
          if(i>=0)
          {
              if (i + 3 < len)
              {
                  num3 = num.Substring(i, 3);
              }
              else
              {
                  num3 = num.Substring(i,SysConvert.ToInt32(len)-i);
              }
          }
            else
              {
                  num3 = num.Substring(0, SysConvert.ToInt32(first) + 3);
              }
         string strEng=English(num3);
          if(strEng!="")
          {
           if(strRet!="")
               strRet+="," ;

           strRet += English(num3) + arr1[SysConvert.ToInt32(cols) - j];
          }
         }
         return strRet;
 
    }
    private string  English( string  num)
{
 string strRet="";
 if((num.Length==3)&&(num.Substring(0,3)!="000"))
 {
  if((num.Substring(0,1)!="0"))
  {
   strRet+=arr3[SysConvert.ToInt32( num.Substring(0,1))]+" HUNDRED";
   if(num.Substring(1,2)!="00")
       strRet+=" AND ";
  }
  num=num.Substring(1);
 }
     if((num.Length==2))
     {
      if((num.Substring(0,1)=="0"))
      {
          num = num.Substring(1);
      }
      else if ((num.Substring(0, 1) == "1"))
      {
          strRet += arr4[SysConvert.ToInt32(num.Substring(1, 1))];
      }
      else
      {
          strRet += arr2[SysConvert.ToInt32(num.Substring(0, 1))];
          if (num.Substring(1, 1) != "0")
           strRet+="-";
       num = num.Substring(1);
      }
     }
 if ((num.Length == 1) && (num.Substring(0, 1) != "0"))
 {
     strRet += arr3[SysConvert.ToInt32(num.Substring(0, 1))];
 }
 return strRet;
}
    #endregion

 

整數部分轉入Translate過程,第一位小數在Arr2中取,第二位小數在Arr3中取。

 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.