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?
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?
是会等于19,那么也就是说系统(7.2-7)*10=1.9
floor(1.9)=1,var
tempInt: double;
i: Integer;
begin
tempInt := (7.2 - 7)* 100;
i := floor(tempInt);
showmessage(IntToStr(i));
end;这样就可以了!呵呵
var
tempInt: integer;
begin
tempInt := Floor((7.2 - 7.0) * 10);
showmessage(IntToStr(tempInt));
end;这样可以,不知什么原因
Floor(1.99999999999)你觉得应该是多少?(7.2-7)*10 = 1.999999999999999999999999999999999999...
(7.2-7)*10 != 2
but why????
你可以找找资料看看浮点数的内存存储方式
其实,浮点数字随着阶码长度和尾数长度不同,其有意义的位数也是不同的.
比如我写的1.999999999999999999999,如果是single类型,有效数字只有8位
也就是 1.9999999469584和1.999999904343543在内存中的表示是无区别的,
换个角度说19999999324.0和119999999444也是没有区别的.
procedure TForm1.Button1Click(Sender: TObject);
var
a, b: single;//double
begin
a := 0.5000000001;
b := 0.5;
if a = b then
ShowMessage('ok');end;类型分别换成single和double是有不同结果的,如果你不明白浮点数的话,会认为在single的情况下,delphi又出bug了.
无论 a:=0.500000003241342141234....后面怎么写
a = b都是成立的
因为,在内存中他们是一样的
看了上面的文章,发现对于对于float认识太浅薄了,揭帖,给分,留解决方案。
floor = round(x - 0.5);
ceil = round(x + 0.5);