[Lazarus] Problem rounding values at post

Allan E. Registos allan.registos at smpc.steniel.com.ph
Wed Jun 4 09:47:24 CEST 2014


On Wednesday, 04 June, 2014 06:03 AM, Philippe wrote:
>
> generally, if one needs accurate values he does not use real values
> ... use integer (or word, longint, longword etc) ... then when needed
> make the conversion or formating (for computing or printing) ...
>
My thinking is quite the opposite. I am not a mathematician though. :)
What if we need a high degree of precision in our computation?  So we
need this type of figure: #####.##### the more precision(accuracy) we
need, the more digits we add after the decimal point.  Integer store
whole numbers w/o any fraction components.
Since I am using PosgreSQL, according to the docs:

"The type numeric can store numbers with a very large number of digits
and perform calculations exactly. It is especially recommended for
storing monetary amounts and other quantities where exactness is
required. However, arithmetic on numeric values is very slow compared to
the integer types, or to the floating-point types described in the next
section. "

The numeric data type must be equivalent of Firebird's decimal data type.

> (it may exists another solution ... someone else may help better for
> that!)
>
> Philippe
>
> Em 03.06.2014 17:39, Daniel Erles escreveu:
>
>> 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.
>>
>> --
>> _______________________________________________
>> Lazarus mailing list
>> Lazarus at lists.lazarus.freepascal.org <mailto:Lazarus at lists.lazarus.freepascal.org>
>> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>
>  
>
>
>
> --
> _______________________________________________
> Lazarus mailing list
> Lazarus at lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20140604/7b4fb071/attachment-0003.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4267 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20140604/7b4fb071/attachment-0003.bin>


More information about the Lazarus mailing list