[Lazarus] Problem rounding values at post
A. Fortuny
aforsprl at gmail.com
Wed Jun 4 11:15:12 CEST 2014
Le 3/06/2014 22:39, Daniel Erles a écrit :
> Hello.
> I have this problem:
>
> My database (Firebird) has a table with the following fields:
> ...
> rTitle DECIMAL(8,4) not null,
> rDiameter DECIMAL(10,6) not null,
> ...
>
> In my program I have a Form with a a TZTable object (ZEOS) called
> zData, bound to that table.
> In a routine I have the following code:
>
> zData.Insert;
> ...
> zData.FieldByName('rTitle').AsFloat := 0.12;
> zData.FieldByName('rDiameter').AsFloat := 0.12;
> ...
> zData.Post;
>
> Then, at the table, I see that the values are stored as follows:
>
> rTitle = *0.1199*
> rDiameter = 0.12
>
> Do not know why rTitle is 0.1199 instead of 0.12
> I need the saved values are accurate.
> I've tried AsFloat, AsCurrency, Value, always with the same result.
>
> Any idea?
>
> Tks.
> Daniel.
>
>
Well it's not easy indeed. In the case of Firebird (it's salso my case)
you have to take into account the sql dialect which makes a big
difference when interfacing numeric values. With sql dialect 1 all
numeric (and decimal) types are output as binary floating point (sirgle
or double dependgng on column precision) figures. In sql dialect 3
decimal, numeric, money and dates are output as integer values ranging
from single byte to int64 with all integer values in between, all
depending on database presions (dates are always output as int64). This
means that there are always fixed implied decimal positions. Have a look
in http://ibexpert.net/ibe/index.php?n=Doc.SQLDialect . There are some
other differences as well.
On the other side with Lazarus (even Delphi) the recipent containers are
always double or extended depending on the interface used, leading to
TFloatField definitions anyway. Sometimes a TBCDField is implemented. In
all this stuff I've been used to use the math function RoundTo as the
number of decimals is always known (think on accounting computations,
invoicing, etc.)..
As a matter of fact, In my developments I always use sql dialect 3 in
the database along with numeric or decimal types when decimals are
needed (read http://www.firebirdfaq.org/faq340/), extended type in
Lazarus and Delphi variables and RoundTo (where applicable) for
intermediate results. There is also a subtle difference in rounding
whether you use bank figures or acconting figures. But that is another story
Antonio.
> --
> _______________________________________________
> Lazarus mailing list
> Lazarus at lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
---
Ce courrier électronique ne contient aucun virus ou logiciel malveillant parce que la protection avast! Antivirus est active.
http://www.avast.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20140604/59ee8194/attachment-0003.html>
More information about the Lazarus
mailing list