weird asfloat and value issue

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
ben
Posts: 119
Joined: Wed 17 Nov 2004 19:48

weird asfloat and value issue

Post by ben » Thu 27 Dec 2007 19:44

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?

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Fri 28 Dec 2007 12:51

This problem is not concerned with float fields, but with peculiarity of how FPU works with Real type.

The following code demonstrate it:

Code: Select all

var
  TotalValue: Real;
begin
  TotalValue := 1.70;
  ShowMessage(FloatToStr(TotalValue - 1.70));
end;

Post Reply