procedure TForm1.cmd2Click(Sender: TObject);
var
str1, str2: string;
LValue1: Double;
LValue2: Extended;
LFactor1: Double;
LFactor2: Extended;
begin
LFactor1 := 0.1;
LFactor2 := 0.1;
LValue1 := 0.15;
LValue2 := 0.15;
LValue1 := (LValue1 / LFactor1) + 0.5;
LValue2 := (LValue2 / LFactor2) + 0.5;
LValue1 := Int(LValue1); //为什么Int(2)=1???
LValue2 := Int(LValue2);
LValue1 := LValue1 * LFactor1;
LValue2 := LValue2 * LFactor2;
str1 := FloatToStr(LValue1);
str2 := FloatToStr(LValue2);
ShowMessage(str1 + '|' + str2);
end;
转载于:https://www.cnblogs.com/IDELPHI/p/6098857.html
本文探讨了在Delphi中使用Int函数进行浮点数取整时遇到的问题,通过具体代码示例展示了Int函数的行为,并解释了为何Int(2)会等于1的现象。文章还涉及了浮点数运算的精度问题以及如何正确处理浮点数的取整操作。
2365

被折叠的 条评论
为什么被折叠?



