金额大小写转换
function My_StrToRMB(curs :string) :string;
implementation
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;