Subject Firebird roundind issues
Author personalsoft_fabiano
Hi all,

I don´t know if this is the right place to post this message, but anyway there it goes...

I´m having rounding issues with Delphi 2007/Zeos 6.6 and Firebird.

When i try to save the extended value '3.26' it stores '3.2599999...'.

Looking at the code, i found a unit where it seems the problem is happening. At least this was the last unit i managed to track.

The code below writes the value to a SQLDA structure, which is unknown for me.

Where can i find info about this structure?
Do someone has advices on how to convert a extended and/or a TBcd to this structure?

Regards,

Fabiano

procedure TZParamsSQLDA.UpdateBigDecimal(const Index: Integer; Value: Extended);
var
SQLCode: SmallInt;
begin
CheckRange(Index);
SetFieldType(Index, sizeof(Int64), SQL_INT64 + 1, -4);
{$R-}
with FXSQLDA.sqlvar[Index] do
begin
if (sqlind <> nil) and (sqlind^ = -1) then Exit;
SQLCode := (sqltype and not(1));

if (sqlscale < 0) then
begin
case SQLCode of
SQL_SHORT : PSmallInt(sqldata)^ := Trunc(Value * IBScaleDivisor[sqlscale]);
SQL_LONG : PInteger(sqldata)^ := Trunc(Value * IBScaleDivisor[sqlscale]);
SQL_INT64,
SQL_QUAD : PInt64(sqldata)^ := Trunc(Value * IBScaleDivisor[sqlscale]);
SQL_DOUBLE : PDouble(sqldata)^ := Value;
else
raise EZIBConvertError.Create(SUnsupportedDataType);
end;
end else
case SQLCode of
SQL_DOUBLE : PDouble(sqldata)^ := Value;
SQL_LONG : PInteger(sqldata)^ := Trunc(Value);
SQL_D_FLOAT,
SQL_FLOAT : PSingle(sqldata)^ := Value;
SQL_BOOLEAN : PSmallint(sqldata)^ := Trunc(Value);
SQL_SHORT : PSmallint(sqldata)^ := Trunc(Value);
SQL_INT64 : PInt64(sqldata)^ := Trunc(Value);
SQL_TEXT : EncodeString(SQL_TEXT, Index, FloatToStr(Value));
SQL_VARYING : EncodeString(SQL_VARYING, Index, FloatToStr(Value));
else
raise EZIBConvertError.Create(SUnsupportedDataType);
end;
if (sqlind <> nil) then sqlind^ := 0; // not null
end;
{$IFOPT D+}
{$R+}
{$ENDIF}
end;