<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<div class="moz-cite-prefix">Le 3/06/2014 22:39, Daniel Erles a
écrit :<br>
</div>
<blockquote
cite="mid:CAFquMp-8sxExAKA99ZQ6QOg1bwLzAXdxvhUXMGvRaT2gr4dRJw@mail.gmail.com"
type="cite">
<div dir="ltr">
<div>Hello. </div>
<div>I have this problem: </div>
<div><br>
</div>
<div>My database (Firebird) has a table with the following
fields: </div>
<div>... </div>
<div>rTitle DECIMAL(8,4) not null,</div>
<div>rDiameter DECIMAL(10,6) not null, </div>
<div>... </div>
<div><br>
</div>
<div>In my program I have a Form with a a TZTable object (ZEOS)
called zData, bound to that table. </div>
<div>In a routine I have the following code: </div>
<div><br>
</div>
<div>zData.Insert;</div>
<div>...</div>
<div>zData.FieldByName('rTitle').AsFloat := 0.12; </div>
<div>zData.FieldByName('rDiameter').AsFloat := 0.12; </div>
<div>...</div>
<div>zData.Post;</div>
<div><br>
</div>
<div>Then, at the table, I see that the values are stored as
follows: </div>
<div><br>
</div>
<div>rTitle = <b>0.1199</b></div>
<div>rDiameter = 0.12 </div>
<div><br>
</div>
<div>Do not know why rTitle is 0.1199 instead of 0.12 </div>
<div>I need the saved values are accurate. </div>
<div>I've tried AsFloat, AsCurrency, Value, always with the same
result. </div>
<div><br>
</div>
<div>Any idea?</div>
<div><br>
</div>
<div>Tks. </div>
<div>Daniel.</div>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
</blockquote>
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 <a
href="http://ibexpert.net/ibe/index.php?n=Doc.SQLDialect">http://ibexpert.net/ibe/index.php?n=Doc.SQLDialect</a>
. There are some other differences as well.<br>
<br>
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.)..<br>
<br>
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 <a href="http://www.firebirdfaq.org/faq340/">http://www.firebirdfaq.org/faq340/</a>),
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<br>
<br>
Antonio.<br>
<blockquote
cite="mid:CAFquMp-8sxExAKA99ZQ6QOg1bwLzAXdxvhUXMGvRaT2gr4dRJw@mail.gmail.com"
type="cite">
<pre wrap="">--
_______________________________________________
Lazarus mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Lazarus@lists.lazarus.freepascal.org">Lazarus@lists.lazarus.freepascal.org</a>
<a class="moz-txt-link-freetext" href="http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus">http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus</a>
</pre>
</blockquote>
<br>
<br /><br />
<hr style='border:none; color:#909090; background-color:#B0B0B0; height: 1px; width: 99%;' />
<table style='border-collapse:collapse;border:none;'>
<tr>
<td style='border:none;padding:0px 15px 0px 8px'>
<a href="http://www.avast.com/">
<img border=0 src="http://static.avast.com/emails/avast-mail-stamp.png" />
</a>
</td>
<td>
<p style='color:#3d4d5a; font-family:"Calibri","Verdana","Arial","Helvetica"; font-size:12pt;'>
Ce courrier électronique ne contient aucun virus ou logiciel malveillant parce que la protection <a href="http://www.avast.com/">Antivirus avast!</a> est active.
</p>
</td>
</tr>
</table>
<br />
</body>
</html>