智
智利
Unregistered / Unconfirmed
GUEST, unregistred user!
有一函数:
Function TfrmWjrkd.CPC_Round_Str(Num:Real48{要取整的数};Digit:Integer{要取取到第几位小数}):string;
var strNum:String;//Num*(Digit+1)
DigitNum:Real;
i:Integer;
ss:string;
begin
DigitNum:=10;
if Digit<0 then
begin
MessageDlg('错误的Digit参数', mtconfirmation,[mbOk], 0);
Exit;
end;
if Digit=0 then
begin
CPC_Round_str:=FloatToStr(Num);
Exit;
end;
for i:=1 to Digit-1 do
begin
DigitNum:=DigitNum*10;
end;
if Num=Round(Num*DigitNum)/DigitNum then /这一句为什么不能相等?/
begin
ss:=FloatToStr((int(Num*(DigitNum)))/(DigitNum));
CPC_Round_Str:=ss;
Exit;
end;
问题就是:这一句为什么不能相等?Num=Round(Num*DigitNum)/DigitNum
设输入的数为2.34,取两位。
Function TfrmWjrkd.CPC_Round_Str(Num:Real48{要取整的数};Digit:Integer{要取取到第几位小数}):string;
var strNum:String;//Num*(Digit+1)
DigitNum:Real;
i:Integer;
ss:string;
begin
DigitNum:=10;
if Digit<0 then
begin
MessageDlg('错误的Digit参数', mtconfirmation,[mbOk], 0);
Exit;
end;
if Digit=0 then
begin
CPC_Round_str:=FloatToStr(Num);
Exit;
end;
for i:=1 to Digit-1 do
begin
DigitNum:=DigitNum*10;
end;
if Num=Round(Num*DigitNum)/DigitNum then /这一句为什么不能相等?/
begin
ss:=FloatToStr((int(Num*(DigitNum)))/(DigitNum));
CPC_Round_Str:=ss;
Exit;
end;
问题就是:这一句为什么不能相等?Num=Round(Num*DigitNum)/DigitNum
设输入的数为2.34,取两位。