Quote:
|
Originally Posted by stolze
If you want to have decimal or float/double precision division, you should do "30.0 / 70" or "30 / 70.0" or "30.0 / 70.0"
|
The last one will still return 0, at least when "30.0" is seen as a DECIMAL(3,1), since division of DECIMALs is essentially division of integers with appropriate before & after shifting of the decimal point.
So, 30.0/70.0 = 300/700 = 0, while 30.0/70 = 300/70 "with shift 1" = 4 "with shift 1" = 0.4
On the other hand, when "30.0" is seen as a float (not a fixed decimal), division is done in "arbitrary precision", and the result is returned as FLOAT, i.e., as something like 0.4285714286
Now the question is: what does DB2 do when it sees 30.0: is it a DECIMAL of a FLOAT?
If you want to be independent of this (at first sight arbitrary) choice, cast your input data yourself:
Code:
CAST(30 AS float) / 70