[Lazarus] Storing currency or real types in a database

Graeme Geldenhuys graemeg.lists at gmail.com
Sat May 30 15:04:17 CEST 2009


2009/5/30 Zaher Dirkey <parmaja at gmail.com>:
> I used Firebird SQL 2.x and use numeric(18,4) for Currency, i have no
> problem because Firebird work on numeric(18,4) as INT64 with special
> convert to try to get and put at the client, in fact Delphi/FPC and

So basically you are also using Integer type to store currency. And
then * or / to convert the 4 digit decimals.

What I didn't mention in my previous post is that recurring decimals
(eg. 1.3333333....) are a real pain when storing as standard floating
point types and causes all kinds of rounding errors in calculations.
We have no decided to trunc our currency values to 2 decimals and use
our own rounding routine (not bankers rounding etc...). When then
convert our currency amounts to integers before they are stored in the
database.

So far this has been keeping use (developers) happy and our company
accountants are also happy with the results.  :-)


Regards,
  - Graeme -


_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/




More information about the Lazarus mailing list