Subject | Re: [IBO] Is CURRENCY field column attributes ignored? |
---|---|
Author | Marco Menardi |
Post date | 2001-11-09T09:22:48Z |
--- In IBObjects@y..., "Geoff Worboys" <geoff@t...> wrote:
IBO does, roughly, something like
tmpCurrency := for i=1 to scale: tmpCurrency := tmpCurrency * 10
this brings tmpCurrency to overflow very easy!
Let's say, for istance, that the limit (overflow) of currency is 1000,
and that we have scale 2 and the number 30.
My code would produce:
tmpINT64=30*100 ----> tmpINT64=3000 that is OK and will be ok when
read since it will be scaled down
IBO code in the loop does in two steps:
tmpCurrency := tmpCurrency * 10 --> Currency = 300
tmpCurrency := tmpCurrency * 10 --> Currency = 3000 OVERFLOW!!!
So my code and IBO are not the same at all.
currency has 3 decimals and numeric(15,2) is used, it will be rounded
to 2 decimals.
Marco Menardi
> > Reading IB6 Data definition guide, you discover that,SQL_INT64
> > for IBO6 and above, numeric data are ALWAYS stored as
> > integer. The precision determinates if INTEGER or
> > INT64 is used. Since IBO knows about data byte
> > occupation in the database (SQLSize, or something like
> > that), EVERY numeric() must be stored as integer.
>
> Its actually the SQLType that is used (SQL_SHORT, SQL_LONG,
> etc). IBO is already handling the situation in this regard.Similar, but not the same:
>
>
> > So there should be a code like:
> > tmpINT64 := CurrencyFieldValue * (Power10Int(scale))
>
> We want to avoid mixing currency (integer) and extended (floating
> point) if possible. Anyway, you will see that IBO is already doing
> something similar.
IBO does, roughly, something like
tmpCurrency := for i=1 to scale: tmpCurrency := tmpCurrency * 10
this brings tmpCurrency to overflow very easy!
Let's say, for istance, that the limit (overflow) of currency is 1000,
and that we have scale 2 and the number 30.
My code would produce:
tmpINT64=30*100 ----> tmpINT64=3000 that is OK and will be ok when
read since it will be scaled down
IBO code in the loop does in two steps:
tmpCurrency := tmpCurrency * 10 --> Currency = 300
tmpCurrency := tmpCurrency * 10 --> Currency = 3000 OVERFLOW!!!
So my code and IBO are not the same at all.
> This does not negate the fact that an overflow can occur if the typeWe must round to scale when assigning to tmpINT64, so if Delphi
> was NUMERIC(18,2) - if database does not restrict the input via a
> check on the domain/field to only 14 digits of whole number.
>
currency has 3 decimals and numeric(15,2) is used, it will be rounded
to 2 decimals.
>Regards
> Geoff Worboys
> Telesis Computing
Marco Menardi