Subject Re: [ib-support] precision between IB & FIB Components
Author Helen Borrie
At 10:05 PM 03-01-02 +0800, you wrote:
>Hello.
>
>Can anybody explain this, ta.
>
>I am experimenting with IBConsole and a Delphi3 test app utilizing FIB components and connecting to the demo EMPLOYEE.GDB that comes with FB.
>
>With...
>
>execute procedure sub_tot_budget('000')
>
>... via IBConsole it correctly returns values with 2 decimal places (defined in StProc as NUMERIC 15,2). Yet in the FIB dataset it shows more than two digit precision, e.g. 1166666.66666667
>
>Is FB sending Delphi (or the FIB dataset) only two decimal places and Delphi/FIB is fiddling with the precision?

Yes: IBConsole is converting it to the Delphi currency type whilst the component is converting it to double or floating point. You can determine which by instantiating the field object using the Fields Editor and examining the DataType property of the object. If FIB supports a BCD TField derivative (binary coded decimal) you can set the field object accordingly, as long as you render the database column (on the server) incapable of storing numbers with more than 14 digits to the left of the decimal point (by applying a CHECK constraint, ideally in a domain definition).

The trap is that, if you don't constrain it, and you manage to store an out-of-range number in the database column, it will overflow the Delphi currency type as soon as those left-hand digits tip over the magic 14 (actually, up to a point, 15 will work but it maxes out somewhere before you get to 10^-16 and 10^16 respectively). IB 6 and Firebird store scaled numerics (numeric and decimal types) as 64-bit integers. Numeric should max out and throw an error if its defined precision is exceeded, but it doesn't, apparently; it behaves just like decimal and keeps accepting significant digits right up to 18.

For a very thorough discussion of the issues in converting IB scaled numerics to Delphi data types, see Geoff Worboys' paper "Working with Currency and Scaled Numeric Data Types" on the tech info page of the IBO website ( http://www.ibobjects.com/TechInfo.html ).

regards,
Helen

All for Open and Open for All
Firebird Open SQL Database ยท http://firebirdsql.org
_______________________________________________________