例如  1236.22  转换成 壹千贰百三拾陆元贰角二分
但实际数据从数据库里调出来的,是动态,应如何实现

解决方案 »

  1.   

    http://borland.mblogger.cn/aiirii/posts/4690.aspx刚刚还看到http://community.csdn.net/Expert/topic/3767/3767631.xml?temp=.8865473
      

  2.   

    为什么这段代码计算出来会错位
    function TForm1.zhuanhuan(i:double):string;
    const
      d='零壹贰叁肆伍陆柒捌玖分角元拾佰仟万拾佰仟亿';
    var
      m,k:string;
      j:integer;
    begin
      k:='';
      m:=floattostr(i*100);
      for j:=length(m) downto 1 do
        k:=k+d[(strtoint(m[Length(m)-j+1])+1)*2-1]+
          d[(strtoint(m[Length(m)-j+1])+1)*2]+d[(10+j)*2-1]+d[(10+j)*2];
      zhuanhuan:=k;
    end;
      

  3.   

    这里也有一个
    http://community.csdn.net/Expert/FAQ/FAQ_Index.asp?id=74647
      

  4.   

    我这里有个函数,你可以试一下:
    Function  TFM_print.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;
      

  5.   

    为什么这段代码计算出来会错位
    function TForm1.zhuanhuan(i:double):string;
    const
      d='零壹贰叁肆伍陆柒捌玖分角元拾佰仟万拾佰仟亿';
    var
      m,k:string;
      j:integer;
    begin
      k:='';
      m:=floattostr(i*100);
      for j:=length(m) downto 1 do
        k:=k+d[(strtoint(m[Length(m)-j+1])+1)*2-1]+
          d[(strtoint(m[Length(m)-j+1])+1)*2]+d[(10+j)*2-1]+d[(10+j)*2];
      zhuanhuan:=k;
    end;当然要出错了,d只是一个字符常量,又没有定义为一个字符类型的数组。
      

  6.   

    //* 小写金额转换为大写
    function UpperMoney(small:real):string;
    var
       SmallMonth,BigMonth:string;
       wei1,qianwei1:string[2];
       qianwei,dianweizhi,qian:integer;
       ObjSmall:real;
    begin
       {------- 修改参数令值更精确 -------}
       ObjSmall:=Abs(small);
       qianwei:=-2;{小数点后的位置,需要的话也可以改动-2值}
       Smallmonth:=formatfloat('0.00',ObjSmall);{转换成货币形式,需要的话小数点后加多几个零}
       {---------------------------------}
       dianweizhi :=pos('.',Smallmonth);{小数点的位置}
       for qian:=length(Smallmonth) downto 1 do{循环小写货币的每一位,从小写的右边位置到左边}
       begin
          if qian<>dianweizhi then{如果读到的不是小数点就继续}
             begin
                case strtoint(copy(Smallmonth,qian,1)) of{位置上的数转换成大写}
                1:wei1:='壹';
                2:wei1:='贰';
                3:wei1:='叁';
                4:wei1:='肆';
                5:wei1:='伍';
                6:wei1:='陆';
                7:wei1:='柒';
                8:wei1:='捌';
                9:wei1:='玖';
                0:wei1:='零';
                end;
                case qianwei of{判断大写位置,可以继续增大到real类型的最大值}
                -3:qianwei1:='厘';
                -2:qianwei1:='分';
                -1:qianwei1:='角';
                0 :qianwei1:='元';
                1 :qianwei1:='拾';
                2 :qianwei1:='佰';
                3 :qianwei1:='千';
                4 :qianwei1:='万';
                5 :qianwei1:='拾';
                6 :qianwei1:='佰';
                7 :qianwei1:='千';
                8 :qianwei1:='亿';
                9 :qianwei1:='十';
                10:qianwei1:='佰';
                11:qianwei1:='千';
                end;
                inc(qianwei);
                if Small<0 then
                   BigMonth :='负'+wei1+qianwei1+BigMonth {组合成大写金额}
                else
                   BigMonth :=wei1+qianwei1+BigMonth {组合成大写金额}
             end;
       end;
       Result:=BigMonth;
    end;