| function fAmt2ChStr(ls:Variant): String;
 var //Knight.Chen
 dx_sz,dx_dw,str_int,str_dec,dx_str,fu:AnsiString;
 a,b,b2,c,d:AnsiString;
 num_int,num_dec,len_int,i,a_int,pp:longint;
 //dx_str为返回字符串
 begin
 
 try
 ls:=StrToFloat(ls);
 if ls>=10000000000.0 then
 begin
 Result:='[超出最大值:10万亿]';
 Exit;
 end;
 
 except
 Result:='[非法金额数值]';
 Exit;
 end;
 
 //不能超过13位
 
 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:=strtoint64(str_int);
 //取得小数值及小数串
 if (ls>0)and(ls<1) then
 num_dec:=ls*100
 else
 num_dec:=Round((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:=strtoint64(a);
 b:=copy(dx_sz,(a_int*2+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;
 
 //吉林鲍先生说: 30万整,没有"元"显示.
 //但仍有缺陷: 比如: 30000.6, 显示为:3万6角,一样没有"元"显示
 //现在,加下面这句话,就完美了
 if (Copy(WideString(dx_str),Length(WideString(dx_str)),1)<>'元') then
 begin
 dx_str:=dx_str+'元';
 end;
 
 
 //处理金额小于1的情况
 if Length(dx_str)<=2 then dx_str:=';
 //转换小数部分
 if (num_dec<10)and(ls>0) then
 begin
 a_int:=strtoint64(str_dec);
 b:=copy(dx_sz,(a_int*2+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:=strtoint64(copy(str_dec,1,1));
 a:=copy(dx_sz,(a_int*2+1),2);
 a_int:=strtoint64(copy(str_dec,2,1));
 b:=copy(dx_sz,(a_int*2+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;
 
 
 也是网上抄来的, 我略改进了一点点.
 |