Problem with round

15 views
Skip to first unread message

Felix Gonzalez

unread,
May 30, 2023, 4:45:57 AM5/30/23
to firebird-support
Hello
I´ve this procedure

create or alter procedure test
returns(t numeric(12,3))
as
    declare variable a numeric(12,3);
    declare variable b numeric(12,3);
begin
    a=51;
    b=1.65;
    t = a*b;
    suspend;

    t = round(a*b, 1);
    suspend;

    t= a*b;
    t = round(t,  1);
    suspend;

    t=84.150;
    t = round(t,  1);
    suspend;
end

and this are results:
T
84,15
84,1
84,1
84,2

Results 2 and 3 must be 84.2 what I´m doing wrong?
I´ve tested with Fb2.5 and Fb3

Thanks

Mark Rotteveel

unread,
May 30, 2023, 4:55:18 AM5/30/23
to firebird...@googlegroups.com
Works fine for me in Firebird 2.5.9, 3.0.10 and 4.0.2 with a dialect 3
database.

I can reproduce this with a dialect 1 database, which is not surprising,
because there the number is actually a double precision, and 1.65 is not
exactly 1.65 in double precision, and neither is the result of 51 * 1.65
exactly 84.15, but rather closer to 84.14999999999999, so when rounding,
it is rounded down.

You should stop using dialect 1, it was deprecated back in 2000 with
InterBase 6.

Mark
--
Mark Rotteveel

Felix Gonzalez

unread,
May 30, 2023, 4:58:41 AM5/30/23
to firebird-support
Thanks
Reply all
Reply to author
Forward
0 new messages