zoukankan      html  css  js  c++  java
  • C#转换英文大写(两位小数)

     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中取。

  • 相关阅读:
    快捷键
    mongoose--------ORM数据操作框架
    restful-----------------------------接口设计方式(一种风格)
    yarn========================(类似于node)
    npm
    nodejs笔记
    事件委托添加与移除
    JSON基础知识
    json字符串转换为json对象
    CSS3弹性盒模型
  • 原文地址:https://www.cnblogs.com/jacker1979/p/1517528.html
Copyright © 2011-2022 走看看