Rounding issues

In this forum we will discuss things relating the ZEOSLib 6.6.x stable versions

Moderators: gto, EgonHugeist

Post Reply
personalsoft_fabiano
Fresh Boarder
Fresh Boarder
Posts: 15
Joined: 13.02.2009, 18:55
Location: Americana/SP

Rounding issues

Post 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
seawolf
Zeos Dev Team *
Zeos Dev Team *
Posts: 385
Joined: 04.06.2008, 19:50
Contact:

Post by seawolf »

This issue is known and correct

So download lastest svn version or check if version you are using is patched
personalsoft_fabiano
Fresh Boarder
Fresh Boarder
Posts: 15
Joined: 13.02.2009, 18:55
Location: Americana/SP

Post 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;
User avatar
mdaems
Zeos Project Manager
Zeos Project Manager
Posts: 2766
Joined: 20.09.2005, 15:28
Location: Brussels, Belgium
Contact:

Post 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
Image
Post Reply