Subject Re: [IBO] Rounding problem
Author Geoff Worboys
Hi Riho,

> I use FB 1.03, Dialect 1.
> -----------------
> Data is stored in this table:
> CREATE TABLE TRUST_BALANCE (
...
> AVERAGE NUMERIC(15,2),
...

So this means that NUMERIC(15,2) is actually implemented in
the database as a DOUBLE (with special handling in the engine
to try and make it look and act like a scaled integer.

Had the NUMERIC(15,2) been created in dialect 3 then the field
would exist as a scaled INT64 value.

When used by AVG (AFAICT) the result data type will be the same
as the field data type (NUMERIC(15,2) as a double). So what
comes back to the client is a double.


> Field is populated with this row:
> DModul->QTrBalance->FieldByName("AVERAGE")->AsString=
> packet->Find("BAL",Ansi);

Not sure I understand this line but I dont think that it
really matters.

> ------------------
> Query properties:
> object Query: TIB_Query
> ColumnAttributes.Strings = (
> 'SDATE=NOTIME')
> FieldsDisplayFormat.Strings = (
> 'MIN=0.00'
> 'AVG=0.00')
> SQL.Strings = (
> 'SELECT ACCID'
> ' , account.ACCOUNT'
> ' , TRUST_BALANCE.CURRENCY'
> ' , MACCOUNT'
> ' , NAME'
> ' , avg(AVERAGE),min(average)'
> 'FROM TRUST_BALANCE'
> 'JOIN ACCOUNT on TRUST_BALANCE.accid=account.ID'
> 'group by accid, account.ACCOUNT'
> ' , TRUST_BALANCE.CURRENCY'
> ' , MACCOUNT , NAME')
...

So that is the TIB_Query. The other side of the question is
whether you use designtime field definitions in your TIBOQuery
or whether you allow it to be created entirely dynamically.
(I suspect its dynamic since it is probably there just for
the report process.)

If you have not already, you could try adding a
ColumnAttribute of AVG=BCD to the TIBOQuery definition. This
should force the query to implement it as a currency data type
and make it behave the same way as TIB_Query.

> --------------
> In QReport I use TQRDBText:
> object QRDBText2: TQRDBText
> Left = 212
> Top = 0
> Width = 24
> Height = 16
> DataField = 'AVG'
> Mask = '0.00'
> end

Before making the change described above you could also try
changing the Mask = '0.00' to Mask = '0.0000', temporarily,
just to see what value the report is getting. Then make the
change above and see what difference it makes.

--
Geoff Worboys
Telesis Computing