Subject Re: Stored Proc : cast to float?
Author csswa
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
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/> .
>
>
>
>
> [Non-text portions of this message have been removed]