Hello,
I have a table with a value that I can see on the grid its 1.7
I assign the value to a variable
var
TotalValue: Real;
begin
TotalValue := DM.MemberSearch.FieldByName('debt').AsFloat;
ShowMessage(FloatToStr(TotalValue));
and it says 1.70
then I execute the code:
ShowMessage(FloatToStr(TotalValue - 1.70));
and instead of 0 I receive
-4,44522890719057E-17
Very weird because If I change the first line with
TotalValue := StrToFloatDef(DM.MemberSearch.FieldByName('debt').AsString, 0);
The result is 0. Which means that something is wrong with "AsFloat" assignment.
[EDIT] debt field in mysql is Decimal 6,2
Any idea?
weird asfloat and value issue
This problem is not concerned with float fields, but with peculiarity of how FPU works with Real type.
The following code demonstrate it:
The following code demonstrate it:
Code: Select all
var
TotalValue: Real;
begin
TotalValue := 1.70;
ShowMessage(FloatToStr(TotalValue - 1.70));
end;