读书人

Is it delphi`s bug?解决方法

发布时间: 2012-04-01 17:23:46 作者: rapoo

Is it delphi`s bug?????
procedure TForm1.Button1Click(Sender: TObject);
var
tempInt: integer;
begin
tempInt := Floor((7.2 - 7) * 10);
showmessage(IntToStr(tempInt));
end;

//run the procedure behind and tell me why?
//why the result is 1 not 2????
//Is it delphi`s bug?

[解决办法]
不是BUG,是你对浮点数字理解不够。


Floor(1.99999999999)你觉得应该是多少?

(7.2-7)*10 = 1.999999999999999999999999999999999999...
(7.2-7)*10 != 2

读书人网 >.NET

热点推荐