Page 1 of 1

Rounding issues

Posted: 01.07.2009, 15:26
by personalsoft_fabiano
Hi all,

I´m having rounding issues with Zeos and Firebird.

When i set a parameter to 3.26, it stores 3.2599 in the database.

I´m using "PreparedStatement.SetValue(n, DecodeVariant(Value))".

Does someone have these kind of issues? Is it related to Firebird or to Zeos?

I noticed that all Zeos methods used to assign numeric parameter values works with floating point types, including SetBigDecimal, which was supposed to use a decimal type (probably a TBCD in Delphi), so it seems we can have a design problem here.

Is there someone aware of a workaround for my case?

Regards,

Fabiano

Posted: 01.07.2009, 21:31
by seawolf
This issue is known and correct

So download lastest svn version or check if version you are using is patched

Posted: 02.07.2009, 05:31
by personalsoft_fabiano
Hi, Seawolf

I´m afraid there is still something wrong there.
I downloaded the patch from mdaems, recompiled, and 1 of the tests below still writes wrong data to the database
Test1 stores the right value in the database
Test2 stores 3.259999...
It seems the patch treats just field retrieval, not parameters updates.

FIREBIRD: CREATE TABLE T (F NUMERIC(13,4));

uses
ZDbcInterbase6, ZDbcIntfs, ZVariant;

procedure TForm5.Button1Click(Sender: TObject);
var
C: IZConnection;
P: IZPreparedStatement;
Value: Extended;
begin
Value := 3.26;

C := DriverManager.GetConnection('zdbc:firebird-2.0://127.0.0.1/tecelagem?UID=sysdba;PWD=masterkey');
C.Open;

// Test1 - WRITES 3.26
P := C.PrepareStatement('insert into t values (?)');
P.SetBigDecimal(1, Value);
P.ExecutePrepared;

// Test2 - WRITES 3.2599
P := C.PrepareStatement('insert into t values (?)');
P.SetValue(1, DecodeVariant(Value));
P.ExecutePrepared;
end;

Posted: 08.07.2009, 22:00
by mdaems
Hi Fabiano,

Please have a look at
TZInterbase6PreparedStatement.BindInParameters (for Zeos 7.X) or PrepareParameters in unit ZDbcInterbase6Utils.pas (Zeos 6.6.X).

I think the problem is in the way Float paramters are mapped to bind variables.

Mark