Subject | Re: how to calculate |
---|---|
Author | Adam |
Post date | 2007-08-05T00:24:23Z |
> if i do SELECT (1800/3600)*10 FROM RDB$DATABASE the result is 0.The SQL standard defines the division of 2 integers to return an
integer. Thus 1800/3600 will return 0. 0 multiplied by anything = 0.
So Firebird is correct as per the SQL standard. Whether the SQL
standard makes sense is a question for another day.
> how do i get 5?You need to make sure you are not dividing an integer by an integer.
>
This can be done by adding a decimal point if they are constants
eg:
1800.0 / 3600
or
1800 / 3600.0
If they are integer fields you are trying to divide, then you can use
cast.
cast(1800 as float) / 3600
Note that only one of the fields needs to be float or numeric to avoid
the integer division.
Adam