在网易的广州社区里面的delphi论坛里面有这个函数哦!!记得加分

解决方案 »

  1.   

    编写函数:
    Function  TFormFhdCw.XxToDx(const hjnum:real):String;
    var Vstr,zzz,cc,cc1,Presult:string;
        xxbb:array[1..12]of string;
        uppna:array[0..9] of string;
        iCount,iZero,vPoint,vdtlno:integer;
    begin
      //*设置大写中文数字和相应单位数组*//
      xxbb[1]:='亿';
      xxbb[2]:='仟';
      xxbb[3]:='佰';
      xxbb[4]:='拾';
      xxbb[5]:='万';
      xxbb[6]:='仟';
      xxbb[7]:='佰';
      xxbb[8]:='拾';
      xxbb[9]:='元';
      xxbb[10]:='.';
      xxbb[11]:='角';
      xxbb[12]:='分';
      uppna[0]:='零';
      uppna[1]:='壹';
      uppna[2]:='贰';
      uppna[3]:='叁';
      uppna[4]:='肆';
      uppna[5]:='伍';
      uppna[6]:='陆';
      uppna[7]:='柒';
      uppna[8]:='捌';
      uppna[9]:='玖';
      Str(hjnum:12:2,Vstr);
      cc:='';
      cc1:='';
      zzz:='';
      result:='';
      presult:='';
      iZero:=0;
      vPoint:=0;
      for iCount:=1 to 10 do
        begin
          cc:=Vstr[iCount];
          if cc<>' ' then
            begin
              zzz:=xxbb[iCount];
              if cc='0' then
              begin
                if iZero<1 then  //*对“零”进行判断*//
                   cc:='零'
                else
                   cc:='';
                if iCount=5 then     //*对万位“零”的处理*//
                   if copy(result,length(result)-1,2)='零' then
                      result:=copy(result,1,length(result)-2)+xxbb[iCount]
    +'零'
                   else
                      result:=result+xxbb[iCount];
                cc1:=cc;
                zzz:='';
                iZero:=iZero+1;
              end
              else
                begin
                  if cc='.' then
                    begin
                      cc:='';
                      if (cc1='') or (cc1='零')  then
                      begin
                         Presult:=copy(result,1,Length(result)-2);
                         result:=Presult;
                         iZero:=15;
                      end;
                      if iZero>=1 then
                         zzz:=xxbb[9]
                      else
                         zzz:='';
                      vPoint:=1;
                    end
                  else
                    begin
                      iZero:=0;
                      cc:=uppna[StrToInt(cc)];
                    end
                end;
              result:=result+(cc+zzz)
            end;
        end;
        If Vstr[11]='0' then   //*对小数点后两位进行处理*//
        begin
           if Vstr[12]<>'0' then
           begin
              cc:='零';
              result:=result+cc;
              cc:=uppna[StrToInt(Vstr[12])];
              result:=result+(uppna[0]+cc+xxbb[12]);
           end
        end
        else
        begin
           if iZero=15 then
           begin
              cc:='零';
              result:=result+cc;
           end;
           cc:=uppna[StrToInt(Vstr[11])];
           result:=result+(cc+xxbb[11]);
           if Vstr[12]<>'0' then
           begin
              cc:=uppna[StrToInt(Vstr[12])];
              result:=result+(cc+xxbb[12]);
           end;
        end;
      result:=result+'正';
    end;试试吧!
      

  2.   

    请看看我这样的转大写有什么错?
    function Tform1.toupper(const hjnum:real):string;
    var
    xxbb:array[1..12] of string;
    uppna:array[0..9] of string;
    icount,i:integer;
    cc1,cc,vstr:string;begin
     xxbb[1]:='亿';
     xxbb[2]:='仟';
     xxbb[3]:='佰';
     xxbb[4]:='拾';
     xxbb[5]:='万';
     xxbb[6]:='仟';
     xxbb[7]:='佰';
     xxbb[8]:='拾';
     xxbb[9]:='元';
     xxbb[10]:='.';
     xxbb[11]:='角';
     xxbb[12]:='分';
     uppna[0]:='零';
     uppna[1]:='壹';
     uppna[2]:='贰';
     uppna[3]:='叁';
     uppna[4]:='肆';
     uppna[5]:='伍';
     uppna[6]:='陆';
     uppna[7]:='柒';
     uppna[8]:='捌';
     uppna[9]:='玖';
     vstr:='';
     str(hjnum:12:2,cc);
     if cc<>'' then
       begin
         for icount:=(13-length(cc)) to length(cc)-3 do
           begin
            cc1:=cc[icount];
            //if cc1<>'' then
            if ((strtoint(cc1)>=0) and (strtoint(cc1)<=9)) then
              vstr:=vstr+uppna[strtoint(cc1)]+xxbb[icount];
           end;
         i:=11;
         for icount:=(length(cc)-1) to length(cc) do
           begin
             cc1:=cc[icount];
            /// if cc1<>'' then
             if ((strtoint(cc1)>=0) and (strtoint(cc1)<=9)) then
              vstr:=vstr+uppna[strtoint(cc1)]+xxbb[i];
              i:=I+1;
           end;
       end
       else
       vstr:='零元零角零分';
    result:=vstr;
    end;