Subject Odd calculations in select statement
Author scyre9
Odd calculations in select statement

Hello! I am new to this list, and I hope it's the right place for my question.

My original intention was to round numeric values via SQL by multiplying them with 100, then casting the result to integer, and finally dividing the new integer by 100. Then I noticed this strange inconsistency. Here's my test scenario:


create table testtable (testvalue numeric(15, 2));
commit work;
insert into testtable (testvalue) values (52.5);


Running this query against any FB 1.5/2.0 engine...


select
testvalue * 1.19,
cast(testvalue * 100 * 1.19 as integer),
cast(testvalue * 1.19 * 100 as integer),
cast(1.19 * 100 * testvalue as integer),
cast(1.19 * testvalue * 100 as integer),
cast(62.475 * 100 as integer)
from testtable

...results in this:

F_1 CAST CAST1 CAST2 CAST3 CAST4
62,475 6248 6247 6248 6247 6248


I wonder whether this a known bug/issue? Any comments appreciated!


Greetings
Thomas