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

  • 相关阅读:
    技术周刊 · 耿耿星河欲曙天 | SpaceX 上的前端架构;跨平台新选择;开源世界的新“大门”;用户推荐算法的敲门砖……
    说说SVG的feTurbulence滤镜
    机器学习进阶
    小程序与动画的故事
    技术周刊 · 迢迢山径峻 | Web 开发成长图谱;下一代前端构建技术;AI 应用下支离破碎的真实;不懂产品不会开发;虚拟货币是新时代的黄金
    从中断机制看 React Fiber 技术
    三分钟了解数字人民币
    凹凸技术揭秘:如何服务 toG 项目——数字人民币项目前端总结
    使用 Phaser3+Matter.js 实现“合成大西瓜”游戏
    痞子衡嵌入式:快速定位i.MXRT600板级设计ISP[2:0]启动模式引脚上电时序问题的方法
  • 原文地址:https://www.cnblogs.com/jacker1979/p/1517528.html
Copyright © 2011-2022 走看看