I'm getting an invalid calculation result when using the double type in Delphi XE2. Below is code to a very simple calculation that should result in zero. Instead, it is returning -1.13686837721616E-13 which is incorrect.
var
dblValue1, dblValue2, dblValue3, dblTotal: double;
begin
try
dblValue1 := 1671.37;
dblValue2 := 871.37;
dblValue3 := 800.00;
dblTotal := (dblValue1 - dblValue3);
dblTotal := (dblTotal - dblValue2);
Write(FloatToStr(dblTotal));
ReadLn;
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
This fails the same way with either a 32 or 64 bit build.
Why does this calculation fail?