function SmallToBig(num:integer):string;
var
temp:string;
i:integer;
a array[1..9] of string;//将A付值为' ','十','百'...
begin
temp:=inttostr(num)
result:='';
for i:=length(temp)-1 to 0 do
begin
result:=a[i]+result;
case strtoint(temp[i]) of
1: result:='一'+result;
.
.
.
end;
end;
end;
时间匆忙,随便写了一个,可能有错误的地方,但经过修改应该可以解决你的问题!
var
temp:string;
i:integer;
a array[1..9] of string;//将A付值为' ','十','百'...
begin
temp:=inttostr(num)
result:='';
for i:=length(temp)-1 to 0 do
begin
result:=a[i]+result;
case strtoint(temp[i]) of
1: result:='一'+result;
.
.
.
end;
end;
end;
时间匆忙,随便写了一个,可能有错误的地方,但经过修改应该可以解决你的问题!
在从事与财务相关的软件开发过程中,通常要求将小写金额转换成相应的大写金额,并打印在大写金额栏中。下面是用Delphi3.0编制的一个转换函数,能够方便的在程序中调用,并返回字符串。 1.定义函数num—str function num—str(ls: Variant): String; var dx—sz,dx—dw,str—int,str—dec,dx—str,fu:string; a,b,b2,c,d:string; num—int,num—dec,len—int,i,a—int,pp:integer; //dx—str为返回字符串 begin dx—sz:=′零壹贰叁肆伍陆柒捌玖′; dx—dw:=′万仟佰拾亿仟佰拾万仟佰拾元′; //处理金额小于零情况 if ls〈0 then begin ls:=ls(-1); fu:=′负′; end else fu:=′′; //取得整数值及整数串 dx—str:=ls; if (ls〉0)and(ls〈1) then dx—str:=′0′+dx—str; pp:=pos(′.′,dx—str); if pp〉0 then str—int:=copy(dx—str,1,pos(′.′,dx—str)-1) else str—int:=dx—str; num—int:=strtoint(str—int); //取得小数值及小数串 if (ls〉0)and(ls〈1) then num—dec:=ls100 else num—dec:=(ls-num—int)100; str—dec:=inttostr(num—dec); len—int:=Length(str—int); dx—str:=′′; //转换整数部分 for i:=1 to len—int do begin //a为小写数字字符,b为对应的大写字符 //c为对应大写单位,d为当前大写字符串的最后一个汉字 a:=copy(str—int,i,1); a—int:=strtoint(a); b:=copy(dx—sz,(a—int2+1),2); c:=copy(dx—dw,((13-len—int+i-1)2+1),2); if dx—str〈〉′′ then d:=copy(dx—str,Length(dx—str)-1,2) else d:=′′; if (b=′零′)and((d=′零′)or(b=b2)or(c=′元′)or(c=′万′)or(c=′亿′)) then b:=′′; if (a=′0′)and(c〈〉′元′)and(c〈〉万′′)and(c〈〉′亿′) then c:=′′; if ((c=′元′)or(c=′万′)or(c=′亿′))and (d=′零′)and(a=′0′) then begin dx—str:=copy(dx—str,1,Length(dx—str)-2); d:=copy(dx—str,Length(dx—str)-1,2); if ((c=′元′)and(d=′万′))or((c=′万′)and(d=′亿′)) then c:=′′; end; dx—str:=dx—str+b+c; b2:=b; end; //处理金额小于1的情况 if Length(dx—str)〈=2 then dx—str:=′′; //转换小数部分 if (num—dec〈10)and(ls〉0) then begin a—int:=strtoint(str—dec); b:=copy(dx—sz,(a—int2+1),2); if num—dec=0 then dx—str:=dx—str+′整′; if num—dec〉0 then dx—str:=dx—str+′零′+b+′分′; end; if num—dec〉=10 then begin a—int:=strtoint(copy(str—dec,1,1)); a:=copy(dx—sz,(a—int2+1),2); a—int:=strtoint(copy(str—dec,2,1)); b:=copy(dx—sz,(a—int2+1),2); if a〈〉′零′ then a:=a+′角′; if b〈〉′零′ then b:=b+′分′ else b:=′′; dx—str:=dx—str+a+b; end; if ls=0 then dx—str:=′零元整′; dx—str:=fu+dx—str; //函数返回字符串 Result:=dx—str; end; 2.调用方法 函数参数采用Variant类型,调用时参数值可以是实型,也可以是字符串,非常方便,下面举例说明: 新建窗口,在相应pas文件中加入num—str函数,并在窗口中添加Button1和Edit1、Edit2控件,双击Button1输入以下代码,运行程序即可: procedure TForm1.Button1Click(Sender: TObject); begin Edit1.text:=num—str(202055010.32); //也可以在Edit2中输入数串调用 //Edit1.text:=num—str(Edit2.text); end;
var
SmallMonth,BigMonth:string;
wei1,qianwei1:string[2];
wei,qianwei,dianweizhi,qian:integer;
begin
qianwei:=-2; //小数点后的位置,需要的话也可以改动-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)) of//位置上的数转换成大写
1:wei1:='壹'; 2:wei1:='贰';
3:wei1:='叁'; 4:wei1:='肆';
5:wei1:='伍'; 6:wei1:='陆';
7:wei1:='柒'; 8:wei1:='捌';
9:wei1:='玖'; 0:wei1:='零';
end;
case qianwei of//判断大写位置,可以继续增大到real类型的最大值
-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;
function Tform1.SmallTOBig(small:real):string;
var SmallMonth,BigMonth:string;
wei1,qianwei1:string[2];
wei,qianwei,dianweizhi,qian:integer;
begin
{------- 修改参数令值更精确 -------}
qianwei:=-2;{小数点后的位置,需要的话也可以改动-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)) of{位置上的数转换成大写}
1:wei1:='壹';
2:wei1:='贰';
3:wei1:='叁';
4:wei1:='肆';
5:wei1:='伍';
6:wei1:='陆';
7:wei1:='柒';
8:wei1:='捌';
9:wei1:='玖';
0:wei1:='零';
end;
case qianwei of{判断大写位置,可以继续增大到real类型的最大值}
-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;