{用Delphi编写人民币大小写转换程序
在财务管理系统中,有时需要打印大写人民币数字,于是笔者编写了以下一些函数使这一需要得以满足,现介绍如下:
注:copy(2005-Jey-QQ:344430663)本程序在Delphi7、Winwin2000下调试通过。}
function TForm1.shuzi(jey: string):string ;
var
i:integer;
s,s1,s2:integer;
ab:integer;
a,b,s3,s4:string;
begin
i:=1; ab:=0; a:=''; b:='';s:=0;s1:=0;s2:=0;s3:='0';s4:='0';
while i begin
ab:=strtoint(shuzi1(copy(jey,i,2)));
if ab=10000000 then
begin
b:=copy(jey,i+2,length(jey));
a:=copy(jey,1,i-1)+'元';
end;
i:=i+2;
end; //end-- while
if length(b)=0 then b:=jey;
i:=1;
while i begin
s1:=strtoint(shuzi1(copy(b,i,2)));
if s1 in [0..9] then
begin
s:=s1;
end
else
begin
s:=s1*s;
s3:=inttostr((s)+strtoint(s3));
s:=0;
end;
i:=i+2;
end; //end-- while
i:=1;s:=0;s1:=0;s2:=0;
while i begin
s1:=strtoint(shuzi1(copy(a,i,2)));
if s1 in [0..9] then
begin
s:=s1;
end
else
begin
s:=s1*s;
s4:=inttostr((s)+strtoint(s4));
s:=0;
end;
i:=i+2;
end; //end-- while
if length(s4)>1 then
result:=inttostr(strtoint(copy(s4,1,length(s4)-3))*10000+(strtoint(s3)div 1000))
else
result:=inttostr(strtoint(s3)div 1000);
if strtoint(copy(s3,length(s3)-1,1))0 then
result:=result+'.'+copy(s3,length(s3)-2,2)
else if strtoint(copy(s3,length(s3)-2,1))0 then
result:=result+'.'+copy(s3,length(s3)-2,1);
end; //end-- begin
function TForm1.shuzi1(jey: string):string;
var
i:integer;
s:integer;
s1:string;
shu1:array of string[2];
begin
s1:='168';
i:=0;
SetLength(shu1,17);
shu1[16]:='万';shu1[15]:='仟';
shu1[14]:='佰'; shu1[13]:='拾'; shu1[12]:='元';shu1[11]:='角';shu1[10]:='分';
SHU1[0]:='零';SHU1[1]:='壹';SHU1[2]:='贰';SHU1[3]:='叁';SHU1[4]:='肆';
SHU1[5]:='伍';SHU1[6]:='陆';SHU1[7]:='柒';SHU1[8]:='捌';SHU1[9]:='玖';
for i:=0 to 16 do
begin
if jeyshu1[i] then continue;
s:=i;
break;
end;
case s of
0:s1:='0';
1:s1:='1';
2:s1:='2';
3:s1:='3';
4:s1:='4';
5:s1:='5';
6:s1:='6';
7:s1:='7';
8:s1:='8';
9:s1:='9';
10:s1:='10';
11:s1:='100';
12:s1:='1000';
13:s1:='10000';
14:s1:='100000';
15:s1:='1000000';
16:s1:='10000000';
end;
result:=s1;
end;