• 把数字小写转换成大写,把数字转化成英文


    把数字小写转换成大写
     
    方法一,使用系统提供的函数,但是不满足大陆财务的要求。
     
     
    方法二:使用下面的函数。
    英文:
    static str Num2EngStr(real realNum,boolean showNegative=false)
    {
           str aa,bb,T1,T2,T3,B,W,CC,a1;
           int a2,a=0,c=0;
           int V,M;
           real tmpReal;
           boolean IsNegative=false;
           ;
     
           aa='ONE'+strRep(' ',9-strLen('ONE'))+'TWO'+strRep(' ',9-strLen('TWO'))+
           'THREE'+strRep(' ',9-strLen('THREE'))+'FOUR'+strRep(' ',9-strLen('FOUR'))+
           'FIVE'+strRep(' ',9-strLen('FIVE'))+'SIX'+strRep(' ',9-strLen('SIX'))+
           'SEVEN'+strRep(' ',9-strLen('SEVEN'))+'EIGHT'+strRep(' ',9-strLen('EIGHT'))+
           'NINE'+strRep(' ',9-strLen('NINE'))+'TEN'+strRep(' ',9-strLen('TEN'))+
           'ELEVEN'+strRep(' ',9-strLen('ELEVEN'))+'TWELVE'+strRep(' ',9-strLen('TWELVE'))+
           'THIRTEEN'+strRep(' ',9-strLen('THIRTEEN'))+'FOURTEEN'+strRep(' ',9-strLen('FOURTEEN'))+
           'FIFTEEN'+strRep(' ',9-strLen('FIFTEEN'))+'SIXTEEN'+strRep(' ',9-strLen('SIXTEEN'))+
           'SEVENTEEN'+strRep(' ',9-strLen('SEVENTEEN'))+'EIGHTEEN'+strRep(' ',9-strLen('EIGHTEEN'))+
           'NINETEEN'+strRep(' ',9-strLen('NINETEEN'));
           bb="TWENTY THIRTY FORTY FIFTY SIXTY SEVENTYEIGHTY NINETY ";
     
           if (realNum==0)
           return 'ZERO ONLY.';
           if (realNum<0)
           {
                  realNum=abs(realNum);
                  IsNegative=true;
           }
           tmpReal=decRound(realNum,2);
           T1=strLtrim(num2str(tmpReal,20,2,1,0));
           T2='';
           T3=T1;
           if (strFind(T3,'.',1,20)!=0)
           {
                  V=strFind(T3,'.',1,20);
                  T1=subStr(T3,1,V-1);
                  T2=subStr(T3,V+1,strLen(T3)-V);
           }
     
           T1=strRep(' ',10 - strLen(T1))+T1;
           CC=T1;
           B='';
           W='';
           M=9;
           while (m >0)
           {
           if (subStr(cc,m+1,1)==' ')
           break;
           if (str2num(subStr(cc,m - 1,3))!=0)
           {
                  if (m==6)
                  W=' THOUSAND '+w;
                  else if (m==3)
                  W=' MILLION '+w;
     
                  A=str2Num(subStr(cc,m,2));
                  if (a !=0)
                  {
                         if (a< 20)
                         B=strRtrim(subStr(aa,(a - 1)*9+1,9));
                         else
                         {
                                A1=strLtrim(num2str(a,20,0,1,0));
                                A2=str2Num(subStr(a1,1,1));
                                b=strRtrim(subStr(bb,(a2 - 2)*7+1,7));
                                a2=str2num(subStr(a1,2,1));
                                if (a2!=0)
                                B=strRtrim(b+'-'+subStr(aa,(a2 - 1)*9+1,9));
     
                         }
                         w=b+w;
                  }
     
                  A=str2num(subStr(cc,m - 1,1));
                  if (a!=0)
                  {
                         b=strRtrim(substr(aa,(a - 1)*9+1,9))+' HUNDRED ';
                         if (w!=' ' && m==9)
                         b=b+'AND ';
                         w=b+w;
                  }
           }
           m=m - 3;
           }
           if (w==' ')
           w='ZERO';
           if (t2!=' ' && t2!='00')
           w=strRtrim(strLtrim(w))+' '+t2+'/100';
           if (substr(w,strLen(w)-11,12)=='HUNDRED AND ')
           w=substr(w,1,strLen(w)-5);
           if(isNegative&&showNegative)
           return 'NEGATIVE '+w+' ONLY.';
           else
           return w+' ONLY.';
     
    }
     
    简体中文:
    static str Num2ChnStr(real realNum)
    {
           real y;
           int b,a;
           str je,x,hz1,hz2,e,h,f,m;
           boolean IsNegative=false;
     
           if (realNum==0)
           return '零园';
           if (realNum<0)
           {
                  realNum=abs(realNum);
                  IsNegative=true;
           }
     
           y=realNum;
           x=strLtrim(strRtrim(num2str(y,20,2,1,0)));
           b=strLen(x)-3;
           a=1;
           e=substr(x,a,1);
           hz2='零壹贰叁肆伍陆柒捌玖';
           hz1='仟佰拾亿仟佰拾万仟佰拾园';
           je='';
           while (e!='.')
           {
                  h=subStr(hz2,str2num(e)*2+1,2);
                  f=subStr(hz1,24-(b-a)*2-1,2);
                  if (e!='0' || (e=='0' && (f=='亿' || f=='万' || f=='园')))
                  je=strLtrim(strRtrim(je))+h+f;
                  else
                  je=strLtrim(strRtrim(je))+h;
                  a=a+1;
                  e=subStr(x,a,1);
           }
           a=a+1;
           e=subStr(x,a,1);
           h=subStr(x,a+1,1);
           if (e=='0' && h=='0')
           je=je+'整';
           else
           {
                  if (e=='0')
                  je=je+'零'+subStr(hz2,str2num(h)*2+1,2)+'分';
                  else if (h=='0')
                  je=je+substr(hz2,str2num(e)*2+1,2)+'角整';
                  else
                  je=je+substr(hz2,str2num(e)*2+1,2)+'角'+subStr(hz2,str2num(h)*2+1,2)+'分';
           }
           b=strLen(je);
           a=1;
           while (a<b)
           {
                  m=substr(je,a,4);
                  if (m=='零园' || m=='零万' || m=='零亿' || m=='零零')
                  {
                         je=subStr(je,1,a-1)+strLtrim(strRtrim(substr(je,a+2,40)));
                         a=a-2;
                         b=b-2;
                  }
                  a=a+2;
           }
     
           if (subStr(je,1,2)=='园' && strLen(je)>2)
           je=subStr(je,3,strLen(je)-2);
           if (IsNegative)
           je='负'+je;
           return je;
    }
  • 相关阅读:
    理解java的接口和抽象类
    Yum 仓库配置
    Vsftp 服务配置
    SAMBA 服务配置
    DHCP 服务配置
    dd 命令的使用
    linux 账户控制
    CentOS 系统优化
    Page Cache与Page回写
    TCP拥塞控制
  • 原文地址:https://www.cnblogs.com/Fandyx/p/2761594.html
Copyright © 2020-2023  润新知