Subject Re: [firebird-support] Re: The integer part of a number
Author Mauricio Bornacin
Thanks Adam for your fast response.
I was able to understand that both 24/60 and the result was considered by the procesor as in integer notation.
Mauricio

Adam <s3057043@...> escribió:
--- In firebird-support@yahoogroups.com, "mauriciobornacin"
<mauriciobornacin@...> wrote:
>
> Can anybody explain why
> select cast(((24/60) + 0.495)as integer ) from table;
> equals 0 and
> select cast(((24/60) + 0.5)as integer ) from table;
> equals 1

Yes.

Under the SQL standard, integer / integer the truncated division as an
integer. So:

24 / 60 = 0.4 (really) = 0 (according to standard).

You can see this by running:
select 24/60 from RDB$DATABASE;

According to SQL standard, adding an integer to a numeric returns a
numeric, so

0 + 0.495 = 0.495

You can see this by running:
select 0+0.495 from RDB$DATABASE;

Converting from a numeric to an integer rounds the value (pretty sure
that is part of the standard too).

You can see this by running:
select cast(0.499 as Integer) from RDB$DATABASE;
select cast(0.5 as Integer) from RDB$DATABASE;

Combining these three facts shows why you get the result you get.

>
> I'm trying to round on minutes and make a phone rate calculation
>

My guess is that you are not expecting 24/60 to return 0. In this
case, either explicitly cast the numerator or denominator as some sort
of numeric, or implicitly cast it by adding .00000 etc.

Adam





__________________________________________________
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis!
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar

[Non-text portions of this message have been removed]