Hello
Hello,
Below is reproduced on both Delphi 10.2.3 and Delphi 10.2.2.
I expect code to display 1715. I do read 1715 (no decimals) after multiplication on Debug. After Trunc() value is 1714.
I know Trunc() rounds towards zero. It is just there is nothing to round as decimal here.
var
ADouble: Double;
AInteger: Integer;
begin
ADouble := 17.15;
ADouble := ADouble * 100;
AInteger := Trunc(ADouble);
ShowMessage(AInteger.ToString());
end;
Thanks.
Below is reproduced on both Delphi 10.2.3 and Delphi 10.2.2.
I expect code to display 1715. I do read 1715 (no decimals) after multiplication on Debug. After Trunc() value is 1714.
I know Trunc() rounds towards zero. It is just there is nothing to round as decimal here.
var
ADouble: Double;
AInteger: Integer;
begin
ADouble := 17.15;
ADouble := ADouble * 100;
AInteger := Trunc(ADouble);
ShowMessage(AInteger.ToString());
end;
Thanks.
Joseph Mitzen Not really. They can be very useful and often even necessary. But you must know about their peculiarities and limitations.
ReplyDeletestackoverflow.com - Is floating point math broken?
ReplyDeletehttps://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html
ReplyDelete