Subject retrieving size and precision of numeric fields
Author Salim Naufal
I have a database that contains fields of type Numeric(18,2).
Using a TIBOQuery, the corresponding field is a TBCDField having
"Precision"=0 and "Size"=8 instead of 18 and 2 respectively. (Using IBX
components, the resulting TIBBCD Field Precision and Size are correct)

This causes a problem in the following case:

Using ClientDataSets, the resulting precision and size become 32 and 8
respectively. This causes problems in applications where rounding to 2
decimal digits is required. To illustrate this case, take an accounting
program. Sum(Debits) = Sum(Credits). If one is to have a debit of 100.00
which is to be spread on 3 accounts for credits. We should get the
following:

Debit 100.00,
Credit Account 1 = 33.33 ,
Credit Account 2 = 33.33 ,
Credit Account 3 = 33.34 (Which is Debit - Credit Act1 - Credit Act2).

However, using IBO with the ClientDatasets, I get the following:

Debit 100.00,
Credit Account 1 = 33.3333 ,
Credit Account 2 = 33.3333 ,
Credit Account 3 = 33.3334

When the changes are applied to the database, the amounts are rounded and we
get:
Debit 100.00,
Credit Account 1 = 33.33 ,
Credit Account 2 = 33.33 ,
Credit Account 3 = 33.33

Therefore, The Sum(Credits) = 99.99 and not 100

As a result, in order to use IBO in an accounting program, we have to add
additional rounding functions to correct this.

I have uploaded on my site a Delphi 7 project and a database to illustrate
this problem. It illustrates the problem using IBO and also shows the
results using IBX components. The Total Size including the database is 36
KB:

http://www.softnet-eng.com/support/prectest.zip

Simply extract the files to directory c:\PrecTest.


The ideal solution would be to have the IBO fields retrieve the correct
field Precision and Size. How can we achieve this? Are there other
alternatives?