求教!金额小写转换为大写!急用!

解决方案 »

  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  My_StrToRMB(curs: string) :string ;
    var
      daxie,danwei,minuscurs:string;
      i,j,deccount :integer ;
      rmb :int64;begin
      curs:=trim(curs);
      if (curs='-') or (curs='.') or (curs='') then  // '.','-',''错
      begin
        result:='ERROR';
        exit;
      end;
      deccount :=0;
      for i:=1 to length(curs) do
      begin
        if  not (curs[i]  in ['0'..'9','.','-']) then     //'123w2'错
        begin
          result:='ERROR';
          exit;
        end;
        if (curs[i]='.') and (deccount>0) then  //'12313.324.23'错
        begin
          result:='ERROR';
          exit;
        end;
        if (curs[i]='-') and (i>1) then        //'-123-123'错
        begin
          result:='ERROR';
          exit;
        end;
        if curs[i]='.' then  inc(deccount);
      end;
      rmb:=round(StrToFloat(curs)*100);
      minuscurs:='';  //负数标志
      if rmb<0 then
      begin
        minuscurs:='(负数)' ;
        rmb:=(-1)*rmb;
      end;
      if rmb>=1E18 then     //超过9千万亿
      begin
        result:='ERROR';
        exit;
      end;
      curs:='';
      i:=0; j:=0 ;
      while rmb>0 do
      begin
        j:= rmb mod 10;
        case j of
          0 : daxie :='零' ;
          1 : daxie :='壹' ;
          2 : daxie :='贰' ;
          3 : daxie :='叁' ;
          4 : daxie :='肆' ;
          5 : daxie :='伍' ;
          6 : daxie :='陆' ;
          7 : daxie :='柒' ;
          8 : daxie :='捌' ;
          9 : daxie :='玖' ;
        end;
        case i of
          0 : danwei :='分' ;
          1 : danwei :='角' ;
          2 : danwei :='圆' ;
          3 : danwei :='拾' ;
          4 : danwei :='佰' ;
          5 : danwei :='仟' ;
          6 : danwei :='万' ;
          7 : danwei :='拾' ;
          8 : danwei :='佰' ;
          9 : danwei :='仟' ;
          10 : danwei :='亿' ;
          11 : danwei :='拾' ;
          12 : danwei :='佰' ;
          13 : danwei :='仟' ;
          14 : danwei :='万' ;
          15 : danwei :='拾' ;
          16 : danwei :='佰' ;
          17 : danwei :='仟' ;
        end;
        rmb:=rmb div 10;
        if j<>0 then curs:=daxie+danwei+curs;      //该位上不为0
        if (j=0) and (not (i in [2,6,10,14])) then //该位为0,是一般位
            curs:=daxie+curs;
        if (j=0) and  (i in [2,6,10,14]) then      //该位为0,是敏感位
            curs:=danwei+curs;
        inc(i);
      end;
      while pos('零零',curs)>0  do  curs:=stringreplace(curs,'零零','零',[]);
      curs:=stringreplace(curs,'零圆','圆',[]);
      while pos('零万',curs)>0  do curs:=stringreplace(curs,'零万','万',[]); //上万亿后可能两个'零万'
      curs:=stringreplace(curs,'零亿','亿',[]);
      curs:=stringreplace(curs,'角零','角整',[]);
      if copy(curs,length(curs)-3,4)='圆零' then  //最后两位是圆零.
          curs:=stringreplace(curs,'圆零','圆整',[]);  //小数点后
      curs:=stringreplace(curs,'亿万','亿',[]);
      result:=minuscurs+curs;
    end;
      

  3.   

    http://www.pconline.com.cn/pcedu/empolder/gj/delphi/0210/96649.html