Posted on 2005-11-14 16:23
貝殼兒 阅读(560)
评论(0) 编辑 收藏 引用 所属分类:
Delphi编程
function SmallToBig(Small:Double): string;
var
i,m:integer;
str:string;
sx:string[14];
x:double;
n:array[1..10] of string;
p:array[1..5] of string;
begin
n[10]:='零'; n[1]:='壹'; n[2]:='貳'; n[3]:='參'; n[4]:='肆'; n[5]:='伍';
n[6]:='陸'; n[7]:='柒'; n[8]:='捌'; n[9]:='玖'; p[1]:='拾'; p[2]:='佰';
p[3]:='仟'; p[4]:='萬'; p[5]:='億';
//-----------------------------------------------------
if small<=9999999999.99 then
begin
x:=small;
sx:=floattostr(int(x));
for i:=1 to 10-length(sx) do
sx:='a'+sx;
{十億位}
if (sx[1]<>'a')and(sx[1]<>'0') then
begin
m:=strtoint(sx[1]);
str:=str+n[m]+p[1];
end;
{億位}
if (sx[2]<>'a')and(sx[2]<>'0') then
begin
m:=strtoint(sx[2]);
str:=str+n[m]+p[5];
end;
if sx[2]='0' then
str:=str+p[5];
{仟萬位}
if (sx[3]<>'a')and(sx[3]<>'0') then
begin
m:=strtoint(sx[3]);
str:=str+n[m]+p[3];
end;
if (sx[3]<>'a')and(sx[3]='0')and(sx[4]<>'0') then
str:=str+'零';
{佰萬位}
if (sx[4]<>'a')and(sx[4]<>'0') then
begin
m:=strtoint(sx[4]);
str:=str+n[m]+p[2];
end;
if (sx[4]<>'a')and(sx[4]='0')and(sx[5]<>'0') then
str:=str+'零';
{拾萬位}
if (sx[5]<>'a')and(sx[5]<>'0') then
begin
m:=strtoint(sx[5]);
str:=str+n[m]+p[1];
end;
if (sx[5]<>'a')and(sx[5]='0')and(sx[6]<>'0') then
str:=str+'零';
{萬位}
if (sx[6]<>'a')and(sx[6]<>'0') then
begin
m:=strtoint(sx[6]);
str:=str+n[m]+p[4];
end
else
if ((sx[3]<>'0')and(sx[3]<>'a'))or((sx[4]<>'0')and(sx[4]<>'a'))or((sx[5]<>'0')and(sx[5]<>'a')) then
str:=str+p[4];
if (sx[6]='0')and(sx[3]='0')and(sx[4]='0')and(sx[5]='0')and(sx[7]<>'0')then
str:=str+'零';
{仟位}
if (sx[7]<>'a')and(sx[7]<>'0') then
begin
m:=strtoint(sx[7]);
str:=str+n[m]+p[3];
end;
if (sx[7]<>'a')and(sx[7]='0')and(sx[8]<>'0') then
str:=str+'零';
{佰位}
if (sx[8]<>'a')and(sx[8]<>'0') then
begin
m:=strtoint(sx[8]);
str:=str+n[m]+p[2];
end;
if (sx[8]<>'a')and(sx[8]='0')and(sx[9]<>'0') then
str:=str+'零';
{拾位}
if (sx[9]<>'a')and(sx[9]<>'0') then
begin
m:=strtoint(sx[9]);
str:=str+n[m]+p[1];
end;
if (sx[9]<>'a')and(sx[9]='0')and(sx[10]<>'0') then
str:=str+'零';
{個位}
if (sx[10]<>'a')and(sx[10]<>'0') then
begin
m:=strtoint(sx[10]);
str:=str+n[m];
end;
//--------------------------------------------------------------
if frac(x)<>0 then
begin
sx:=formatfloat('#.###',(frac(x)));
if length(sx)=2 then
sx:=sx+'0';
if int(x)<>0 then
begin
if (sx[2]<>'0')and(sx[3]<>'0') then
begin
m:=strtoint(sx[2]);
str:=str+'圓'+n[m]+'角';
m:=strtoint(sx[3]);
str:=str+n[m]+'分整';
end;
if (sx[2]='0')and(sx[3]<>'0') then
begin
m:=strtoint(sx[3]);
str:=str+'圓零'+n[m]+'分整';
end;
if (sx[2]<>'0')and(sx[3]='0') then
begin
m:=strtoint(sx[2]);
str:=str+'圓'+n[m]+'角整';
end;
if (sx[2]='0')and(sx[3]='0') then
begin
str:=str+'圓整';
end;
end;
if int(x)=0 then
begin
if (sx[2]<>'0')and(sx[3]<>'0') then
begin
m:=strtoint(sx[2]);
str:=str+n[m]+'角';
m:=strtoint(sx[3]);
str:=str+n[m]+'分整';
end;
if (sx[2]='0')and(sx[3]<>'0') then
begin
m:=strtoint(sx[3]);
str:=str+n[m]+'分整';
end;
if (sx[2]<>'0')and(sx[3]='0') then
begin
m:=strtoint(sx[2]);
str:=str+n[m]+'角整';
end;
if (sx[3]='0')and(sx[4]='0') then
begin
str:=str+'';
end;
end;
end
else
if int(x)<>0 then
str:=str+'圓整';
smalltobig:=str;
end
else
Application.MessageBox('超出範圍,不能轉換!!!',Pchar(Application.Title),MB_OK+MB_ICONWARNING);
end;