Delphi 2009 BUG
输入123,输出壹佰贰拾叁元整
在D7中可以,很好用,但D2009输出乱七八糟,那位高人可以分析下哪儿的问题?!
-------------------------------------------------------------------------
function toChineseCapitalMoney(const Num:double):string;
const
mnUnit:string='分角元';
hzUnit:string='拾佰仟万拾佰仟亿拾佰仟万拾佰仟';
hzNum:string='零壹贰叁肆伍陆柒捌玖';
var
szChMoney,szNum:string;
iLen, iNum, iAddZero,i:integer;
function DRound(Value:double;cnt:byte):double;
var
fTmp:double;
nTmp:double;
k:int64;
begin
Result:=Value;
if cnt>18 then exit;
nTmp:=Power(10.0,cnt);
fTmp:=0.5;
fTmp:=fTmp/nTmp;
Result:=fTmp+Result;
Result:=Result*nTmp;
k:=0;
asm
fld qword ptr Result
//__ftol begin
push ebp
mov ebp,esp
LEA ESP,k
wait
fstcw word ptr [ebp-$04]
wait
mov al,[ebp-$03]
or [ebp-$04],$00000c01
fldcw word ptr [ebp-$04]
fistp qword ptr [ebp-$0c]
mov [ebp-$03],al
fldcw word ptr [ebp-$04]
mov eax ,[ebp-$0c]
mov edx,[ebp-$08]
mov esp,ebp
pop ebp
//__ftol end
push esp
lea esp,k
mov [esp],eax
add esp,4
mov [esp],edx
mov esp,ebp
pop esp
fild qword ptr k
fstp qword ptr Result
fld qword ptr nTmp
fdivr qword ptr Result
fstp qword ptr Result
end;
end;
begin
iAddZero:=0;
szNum:=FormatFloat('0', DRound(Num,2)*100.0); //这样可能会有数字误差,double只有15位有效数字,这里只有13
Result:='';
iLen:=Length(szNum);
if Pos('E',UpperCase(szNum))>0 then exit;
if (iLen>18) or (iLen=0) or (Num<0) then exit; //数据错误返回
for i:=1 to iLen do
begin
iNum:=StrToInt(copy(szNum,i,1));
if iNum=0 then
begin
if (((iLen-i-2) mod 4)=0) and ((iLen-i-3)>0) and (((iLen-i)>=8) or (iAddZero<3)) then
szChMoney:=copy(szChMoney+hzUnit,((iLen-i-3) mod 8)*2+1,2);
inc(iAddZero);
end
else
begin
if ((iAddZero>0) and ((iLen-i)>=2)) and (((iLen-i-1) mod 4)<>0) then
szChMoney:=szChMoney+copy(hzNum,1,2);
szChMoney:=szChMoney+copy(hzNum,iNum*2+1,2);
iAddZero:=0;
end;
if (iAddZero<1) or ((iLen-i)=2) then
if (iLen-i)>=3 then
begin
szChMoney:=szChMoney+copy(hzUnit,((iLen-i-3) mod 8)*2+1,2);
end
else
szChMoney:=szChMoney+copy(mnUnit,((iLen-i) mod 3)*2+1,2);
end;
if Trim(szChMoney)='' then
szChMoney:='零元整'
else
if copy(szNum,Length(szNum),1)='0' then szChMoney:=szChMoney+'整';
Result:=szChMoney;
end;
------------------------
在D7中可以,很好用,但D2009输出乱七八糟,那位高人可以分析下哪儿的问题?!
-------------------------------------------------------------------------
function toChineseCapitalMoney(const Num:double):string;
const
mnUnit:string='分角元';
hzUnit:string='拾佰仟万拾佰仟亿拾佰仟万拾佰仟';
hzNum:string='零壹贰叁肆伍陆柒捌玖';
var
szChMoney,szNum:string;
iLen, iNum, iAddZero,i:integer;
function DRound(Value:double;cnt:byte):double;
var
fTmp:double;
nTmp:double;
k:int64;
begin
Result:=Value;
if cnt>18 then exit;
nTmp:=Power(10.0,cnt);
fTmp:=0.5;
fTmp:=fTmp/nTmp;
Result:=fTmp+Result;
Result:=Result*nTmp;
k:=0;
asm
fld qword ptr Result
//__ftol begin
push ebp
mov ebp,esp
LEA ESP,k
wait
fstcw word ptr [ebp-$04]
wait
mov al,[ebp-$03]
or [ebp-$04],$00000c01
fldcw word ptr [ebp-$04]
fistp qword ptr [ebp-$0c]
mov [ebp-$03],al
fldcw word ptr [ebp-$04]
mov eax ,[ebp-$0c]
mov edx,[ebp-$08]
mov esp,ebp
pop ebp
//__ftol end
push esp
lea esp,k
mov [esp],eax
add esp,4
mov [esp],edx
mov esp,ebp
pop esp
fild qword ptr k
fstp qword ptr Result
fld qword ptr nTmp
fdivr qword ptr Result
fstp qword ptr Result
end;
end;
begin
iAddZero:=0;
szNum:=FormatFloat('0', DRound(Num,2)*100.0); //这样可能会有数字误差,double只有15位有效数字,这里只有13
Result:='';
iLen:=Length(szNum);
if Pos('E',UpperCase(szNum))>0 then exit;
if (iLen>18) or (iLen=0) or (Num<0) then exit; //数据错误返回
for i:=1 to iLen do
begin
iNum:=StrToInt(copy(szNum,i,1));
if iNum=0 then
begin
if (((iLen-i-2) mod 4)=0) and ((iLen-i-3)>0) and (((iLen-i)>=8) or (iAddZero<3)) then
szChMoney:=copy(szChMoney+hzUnit,((iLen-i-3) mod 8)*2+1,2);
inc(iAddZero);
end
else
begin
if ((iAddZero>0) and ((iLen-i)>=2)) and (((iLen-i-1) mod 4)<>0) then
szChMoney:=szChMoney+copy(hzNum,1,2);
szChMoney:=szChMoney+copy(hzNum,iNum*2+1,2);
iAddZero:=0;
end;
if (iAddZero<1) or ((iLen-i)=2) then
if (iLen-i)>=3 then
begin
szChMoney:=szChMoney+copy(hzUnit,((iLen-i-3) mod 8)*2+1,2);
end
else
szChMoney:=szChMoney+copy(mnUnit,((iLen-i) mod 3)*2+1,2);
end;
if Trim(szChMoney)='' then
szChMoney:='零元整'
else
if copy(szNum,Length(szNum),1)='0' then szChMoney:=szChMoney+'整';
Result:=szChMoney;
end;
------------------------
...全文
相关推荐
IDEFixPackReg2009.exe delphi 2009 解决bug,支持多开补丁 win10 win7 64位
delphi 2009 解决bug,支持多开补丁 win10 win7 64位
Ehlib 4.3.21 with fullsource and for delphi2009
源代码的开放性也意味着开发者可以及时获取到最新的bug修复和功能增强,保持项目与时俱进。
CoolTrayIcon v4.40 for delphi2009
在Delphi 2009中,它提供了一种简便的方法来实现应用程序的最小化到托盘,从而增强用户体验。
fastreport2.52_for_D2009_FullSoure
在Delphi2009这个版本中,FastReport 2.52版本是一个关键的更新,它专门针对Delphi2009的VCL框架进行了优化和适配,确保了在这一新平台上的兼容性和稳定性。
delphi补丁
在使用补丁时,需要注意的是,非官方或未经验证的补丁可能存在风险,例如引入新的bug或者安全漏洞。因此,建议只使用来自可靠源的补丁,并确保补丁与用户使用的Delphi版本和操作系统版本相匹配。


