fast report 人民币大写for 4+

delphi7年前 (2019)发布 admin
516 0

Function MoneyToCharacter(f : String) : String;
var dx,d2,zs,xs,s1,s2,h,jg:string;
   i,ws,l,w,j,lx:integer;
begin
jg:='';
dx:='';
d2:='';
zs:='';
xs:='';
s1:='';
s2:='';
h:='';    
  f := Trim(f);
  if copy(f,1,1)='0' then begin
    Delete(f,1,1);end
  else ;
  dx:='零壹贰叁肆伍陆柒捌玖';
  d2:='拾佰仟万亿';
  i := Pos('.',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 Pos('万',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:=Pos('零零',jg);
  While j>0 do begin
    jg :=copy(jg, 1, j - 1)+copy(jg,j+2,200);
    j :=Pos('零零',jg);
  end;
  If (Length(jg)>1)And(copy(jg,length(jg)-1,2)='零')Then jg :=copy(jg,1,Length(jg)-2);
  j := Pos('零亿',jg);
  If j > 0 Then jg:=copy(jg,1, j - 1)+copy(jg, j + 2,200);
  //转换小数部分
  If (Length(jg)>1) then    //定义元
     jg :=jg+'元'
  else
     jg:=jg;    
  lx := Length(xs);
  If lx=0Then begin          //如果小数为零
    jg :=jg + '整' ;
  End;
  If lx=1Then begin         //如果小数为一位
    s1:=copy(dx, strtoint(copy(xs,1,1))*2 + 1, 2);
    if s1<>'零' then
      jg := jg+s1+'角'+'整' ;
    if s1='零' then
      jg := jg+'整' ;
  End;
  If lx>=2Then begin        //小数为两位
    s1:=copy(dx, strtoint(copy(xs,1,1))*2 + 1, 2);
    s2:=copy(dx, strtoint(copy(xs,2,1))*2 + 1, 2) ;
    if (s1='零')and (s2='零') then
       jg := jg +'整' ;
    if (s1<>'零')and (s2<>'零') then
       jg := jg +s1+'角'+s2+'分' ;
    if (s1<>'零')and (s2='零') then
       jg := jg +s1+'角'+'整' ;
    if (s1='零')and (s2<>'零') then
       jg := jg +s1+s2+'分' ;
  End;
  result:=jg;
End;    
begin

end.

© 版权声明

相关文章