Subject Re: Stored Proc : cast to float?
Author csswa
Hi Amrita,

Try casting to double precision instead of float (if using dialect
3). Perhaps you are losing control of precision/scale in the
calculation. You could post your table/SP DDL here so we can see
exactly what's going on.

You need to be aware of how the engine handles arithmetic and the
scale of the values generated. There is an excellent -- if
mindbending -- overview of numerics and precision/scale here:

http://www.ibobjects.com/docs/TI_Numerics.rtf

Also, I'll mention this again: beware divide by zero! Make sure you
are not feeding your stored procedure values that will choke because
of this! You will get a similar 'arithmetic overflow' error message
like the one you describe.

Regards,
Andrew Ferguson
-- A day without sunshine is like night.


--- In ib-support@y..., Amrita Chaudhury <achaudhu@s...> wrote:
> I tried both this method and the one suggested by Tony earlier :
> cast(varname to float).
> I am getting a strange error when I change my stored proc to do
that.
>
> Without the cast or the (xx*1.00) approach, the stored proc
executes fine.
> But whenever I try any of these approaches, I het a
> "arithmetic overflow string concatenation " error .
>
> Does anybody know why a cast to float should trigger such error?
>
> Another strange observation is that this error is generated only if
the
> stored proc returns
> rows more than around 50 !!!
>
>
> Please help -
>
> amrita .
>
>
> -----Original Message-----
> From: csswa [mailto:csswa@y...]
> Sent: Saturday, July 06, 2002 4:52 AM
> To: ib-support@y...
> Subject: [ib-support] Re: Stored Proc : cast to float?
>
>
>
> There is another way that bypasses explicit casting. I don't
> recommend it -- I've yet to hear of others doing it this way -- but
> mention it here as a curiosity. When dividing integers you can
> control the scale used by each value by inserting a dummy value:
>
> (FOO_INTEGER1 * 1.00) / (FOO_INTEGER2 * 1.00)
>
> resulting in integer1 getting cast internally to two decimals
places
> and ditto for integer2. The result gives the expected four-digit
> scale. And with this:
>
> (FOO_INTEGER1 * 1.00) / (FOO_INTEGER2 * 1.0)
>
> you get a result with three decimal places.
>
> My 'five-dollar calculator' experience with FB taught me:
>
> * you only need to be cautious with integers (casting) when
dividing,
> and even then only with dialect 3;
> * beware divide by zero!
>
> For your IB edification, here is the DDL illustrating all of the
> above.
>
> CREATE TABLE TEST (
> F_ONE INTEGER,
> F_TWO INTEGER,
> F_THREE COMPUTED BY ((F_ONE * 1.000) / (F_TWO * 1.000)),
> F_FOUR COMPUTED BY ((F_ONE * 1.00) / (F_TWO * 1.00)),
> F_FIVE COMPUTED BY ((F_ONE * 1.00) / (F_TWO * 1.0)));
>
> Hopefully I got all the facts right above, but if not I'm sure the
> gurus here will set me straight.
>
> Regards,
> Andrew Ferguson
> -- Who do you believe - me, or your mother?
>
>
> --- In ib-support@y..., Amrita Chaudhury <achaudhu@s...> wrote:
> > Thanks, that works !!
> >
> > amrita .
> >
> > -----Original Message-----
> > From: Tony Caduto [mailto:tcaduto@a...]
> > Sent: Friday, July 05, 2002 9:06 AM
> > To: ib-support@y...
> > Subject: Re: [ib-support] Stored Proc : cast to float?
> >
> >
> > how about cast(yourfieldorvar as float)
> >
> >
> > >
> > > How can I "cast" the division of two integers to a
> > > float operation ?
> > .
> >
> >
> >
> > Yahoo! Groups Sponsor
> > {short description of image}
> >
> <
http://us.a1.yimg.com/us.yimg.com/a/de/debtscape/dt_59_468x60north.gi
>
<http://us.a1.yimg.com/us.yimg.com/a/de/debtscape/dt_59_468x60north.gi
>
> f>
> >
> >
> > To unsubscribe from this group, send an email to:
> > ib-support-unsubscribe@e...
> >
> >
> >
> > Your use of Yahoo! Groups is subject to the Yahoo! Terms of
Service
> > < http://docs.yahoo.com/info/terms/
<http://docs.yahoo.com/info/terms/> >
> .
> >
> >
> >
> >
> > [Non-text portions of this message have been removed]
>
>
> To unsubscribe from this group, send an email to:
> ib-support-unsubscribe@e...
>
>
>
> Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service
> <http://docs.yahoo.com/info/terms/> .
>
>
>
>
> [Non-text portions of this message have been removed]