如何将一个小写的金额数(比如106.32元)转成大写的金额数,如何用程序来实现?

解决方案 »

  1.   

    借花献佛:function Tform1.SmallTOBig(small:real):string;
    var SmallMonth,BigMonth:string;
    wei1,qianwei1:string[2];
    wei,qianwei,dianweizhi,qian:integer;
    begin
    {------- 修改参数令值更精确 -------}
    {小数点后的位数,需要的话也可以改动该值}
    qianwei:=-2;{转换成货币形式,需要的话小数点后加多几个零}
    Smallmonth:=formatfloat('0.00',small);
    {---------------------------------}dianweizhi :=pos('.',Smallmonth);{小数点的位置}{循环小写货币的每一位,从小写的右边位置到左边}
    for qian:=length(Smallmonth) downto 1 do
    begin
    {如果读到的不是小数点就继续} 
    if qian<>dianweizhi then
    begin{位置上的数转换成大写}
    case strtoint(copy(Smallmonth,qian,1)) of1:wei1:='壹'; 2:wei1:='贰';
    3:wei1:='叁'; 4:wei1:='肆';
    5:wei1:='伍'; 6:wei1:='陆';
    7:wei1:='柒'; 8:wei1:='捌';
    9:wei1:='玖'; 0:wei1:='零';
    end;{判断大写位置,可以继续增大到real类型的最大值,可是谁有那么多钱}
    case qianwei of
    -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);
    BigMonth :=wei1+qianwei1+BigMonth;{组合成大写金额}
    end;end;SmallTOBig:=BigMonth;end;程序调用如下“edit1.text:=SmallTOBig(1234567890.1234);”他自动默认小数点后两位
      

  2.   

    Function XiaoxieToDaxie(f : String) : String;
    var
       Fs,dx,d2,zs,xs,h,jg:string;
       i,ws,{l,}w,j,lx:integer;
    begin
      f := Trim(f);
      if copy(f,1,1)='-' then begin
        Delete(f,1,1);fs:='负';end
      else fs:='';
      dx:='零壹贰叁肆伍陆柒捌玖';
      d2:='拾佰仟万亿';
      i := AnsiPos('.',f);   //小数点位置
      if i = 0 Then
         zs := f     //整数
      else begin
         zs:=copy(f,1,i - 1);  //整数部分
         xs:=copy(f,i + 1,200);
      end;
      ws:= 0; //l := 0;
      for i := Length(zs) downto 1 do begin
        ws := ws + 1; h := '';
        w:=strtoint(copy(zs, i, 1));
        if (w=0) and (i=1) then jg:='零';
        If w > 0 Then
           Case ws of
             2..5:h:=copy(d2,(ws-1)*2-1,2);
             6..8:begin
               h:=copy(d2,(ws-5)*2-1,2);
               If AnsiPos('万',jg)=0 Then h:=h+'万';
               end;
             10..13:h := copy(d2,(ws-9)*2-1, 2);
           End;
        jg:=copy(dx,(w+1)*2-1,2) + h + jg;
        If ws=9 Then jg := copy(jg,1,2) + '亿' + copy(jg,3,200);
      end;
      j:=AnsiPos('零零',jg);
      While j > 0 do begin
        jg := copy(jg, 1, j - 1) + copy(jg, j + 2,200);
        j := AnsiPos('零零',jg);
      end;
      If (Length(jg) > 1) And (copy(jg,length(jg)-1,2)='零') Then jg :=copy(jg,1,Length(jg)-2);
      j := AnsiPos('零亿',jg);
      If j > 0 Then jg := copy(jg,1, j - 1) + copy(jg, j + 2,200);
      //转换小数部分
      lx := Length(xs);
      If lx > 0 Then begin
        jg := jg + '元';
        For i := 1 To lx do begin
          if i=1 then begin
            jg := jg + copy(dx, strtoint(copy(xs,i,1))*2 + 1, 2);
            jg := jg +'角';
          end;
          if i=2 then begin
            jg := jg + copy(dx, strtoint(copy(xs,i,1))*2 + 1, 2);
            jg := jg +'分';
          end;
        end;
        j :=AnsiPos('零角零分',jg);
        if j>0 then jg := copy(jg,1,j-1)+copy(jg,j+8,200)+'整';
        j := AnsiPos('零角',jg);
        if j>0 then jg := copy(jg,1,j-1)+copy(jg,j+4,200);
        j := AnsiPos('零分',jg);
        if j>0 then jg := copy(jg,1,j-1)+copy(jg,j+4,200);
      End
      else
        jg := jg + '元整';
      result := fs+jg;
    end;
      

  3.   

    将阿拉伯数字转换为中文大写数字
    function ChnCurrency(nn: Double): String;
    const   {将阿拉伯数字转换为中文大写数字}
      ChnDgt: array[48..57] of string=('零','壹','贰','叁','肆','伍','陆','柒','捌','玖');
      ChnPwr: array[0..14] of string=('仟','佰','拾','亿','仟','佰','拾','万','仟','佰','拾','元','','角','分');
    //                                 0    1    2    3    4    5    6    7    8    9   10    11  12  13   14
    var
      bSkip: Boolean;
      NumChrs: Pchar;
      rmb: String;
      i: Smallint;
    begin
    // 对0处理
      if nn=0.0 then
      begin
        Result:='零元整';
        exit;
      end;
    //对负数进行处理
      if nn<0.0 then
      begin
        rmb:='负';
        nn:= -nn;
      end
      else rmb:='';  bSkip:=False;
      Result:='';//  Result:='';
    // 对超大数进行处理,  最大数应小于1亿亿
      if nn>=1000000000000.00 then
      begin
        Result:=FloatToStr(nn)+'元';
        exit;
      end;
      NumChrs:=Pchar(Format('%15.2f',[nn])); {将数字转为总长为15的字符串,带两位小数}
      for i:=0 to 14 do
      begin
          if (NumChrs[i]=' ') or (NumChrs[i]='.') then continue;
          if NumChrs[i]='0' then
          begin
            bSkip:=True;
            if i=3 then Result:=Result+ChnPwr[3];   {亿}
            if i=7 then Result:=Result+ChnPwr[7];   //万
            Result:=AnsiReplaceText(Result, '亿万', '亿');//去除“亿万”中的“万”字
            if i=11 then                            //元
            begin
              if Result='' then bSkip:=False else Result:=Result+ChnPwr[11];
            end;
          end
          else
          begin
            if bSkip then Result:=Result+ChnDgt[48];    //加“零”
            bSkip:=False;
            Result:=Result+ChnDgt[Smallint(NumChrs[i])]; //加“大写数字”
            Result:=Result+ChnPwr[i];                    //加“单位”
          end;
      end;
      //最后一位为0时,加"整"
      if NumChrs[14]<'1' then Result:=Result+'整';
      Result:=rmb+Result;
    end;
      

  4.   

    function TForm1.xTOd(i:Real):string; 
    const 
      d='零壹贰叁肆伍陆柒捌玖分角元拾佰仟万拾佰仟亿'; 
    var 
      m,k:string; 
      j:integer; 
    begin 
      k:=''; 
      m:=floattostr(int(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]; 
      xTOd:=k; 
    end; 
      

  5.   

    function SmallToBig(CurMoney:currency):string;
    var
      s1,s2:string;
      StrMoney:string;  //存储字符串型的小写金额
      StrData:string;   //存储每一位转换成的字符串
      OutputMoney:string;  //存储输出结果
      StrLong:integer;     //字符串长
      Position,Point,p:integer;   //当前位置和小数点位置
      Temp:currency;
    begin
      s1:='壹贰叁肆伍陆柒捌玖';
      s2:='元拾佰千万拾佰千亿拾佰千';
      Temp:=CurMoney;
      //判断数值是否符合要求,不合要求退出
      if (CurMoney>=1000000000000) or (CurMoney<=-1000000000000) then
        begin
         ShowMessage('输入的数据超出范围,请重新输入!');
         exit;
        end;
      //将数据转换成字符型
      StrMoney:=FloatToStr(CurMoney);
      //获取字符串串长
      StrLong:=length(StrMoney);
      // 小数点两位以后将被忽略
      if (Pos('.',StrMoney)<>0)  then
        begin
          Point:= Pos('.',StrMoney);
          if (StrLong-Point >2) then
              ShowMessage('小数点两位以后将被忽略!');
        end;
      //将数据转换成格式为0.00的字符串
      StrMoney:=FormatFloat('0.00',Temp);
      //获取小数点位置
      Point:=Pos('.',StrMoney);
      //获取转换格式后的字符串长
      StrLong:=length(StrMoney);
      //开始转换整数部分
      if (CurMoney<0) then P:=2 else P:=1;
      for Position:=p to Point-1 do
        begin
          if StrMoney[Position]='0' then
            begin
              //如果当前位置为0,且在个,万,亿位上时分别进行转换
              case Point-Position of
                1:if StrLong<>4 then  StrData:='元';
                5:if (StrLong>11) and (StrMoney[Position-1]='0') and
                     (StrMoney[Position-2]='0') and (StrMoney[Position-3]='0') and
                     (StrMoney[Position+1]='0') then
                      continue
                  else
                    StrData:='万';
                9:StrData:='亿'
              else
                //如果下一位还是0,则跳过,否则只取其值名
                begin
                  if StrMoney[Position+1]='0' then
                       continue
                  else
                      StrData:='零';
                end;
              end;
              //将转换的字符累加到结果中
              OutputMoney:=OutputMoney +StrData;
            end
          else
            //当前位置不是0,则转换为值名+位名,累加到结果中
            OutputMoney:=OutputMoney+copy(s1,strtoint(StrMoney[Position])*2-1,2)
                         +copy(s2,(Point-Position)*2-1,2);
        end ;
    ////////////////////////////////////////////////////////////////////////////
        //小数部分是否都为0,是则结果加'整',返回结果
        if (StrMoney[Point+1]='0') and  (StrMoney[Point+2]='0')  then
          begin
            if (StrLong=4) and (StrMoney[1]='0') then
              OutputMoney:='零元整'
            else
              if (Temp <0) then OutputMoney:='负'+OutputMoney+'整'  else
              OutputMoney:=OutputMoney+'整';
            SmallToBig:=OutputMoney;
          end
        else
          begin
            //十分位不为0则转换为值名+角,累加到结果中
            if StrMoney[Point+1]<>'0' then
              OutputMoney:=OutputMoney+copy(s1,strtoint(StrMoney[Point+1])*2-1,2)+'角';
            //百分位不为0则转换为值名+分,累加到结果中
            if StrMoney[Point+2]<>'0' then
              OutputMoney:=OutputMoney+copy(s1,strtoint(StrMoney[Point+2])*2-1,2)+'分';
            //返回结果
            if (Temp <0) then SmallToBig:='负'+OutputMoney  else
            SmallToBig:=OutputMoney;
          end;
    end;