Problems with saving a BCD with more than 4 decimal places using TClientdatasets
Posted: Thu 17 Mar 2005 12:28
Hi
I'm currently using the dbExpress driver for MS SQL Server 2.00 with Delphi v6.
I'm trying to save a decimal value with more that 4 decimal places to a SQL Server 2000 table.
The field is declared as
Unit_Charge DECIMAL 19,10
in the SQL Server 2000 table.
I can seem to successfully get the value of the Unit_Charge into the TClientdataset with more than 4 decimal places by
using aABcd when assigning the value (and using variants to successfully convert from EXTENDED to BCD)
eg
-------------------------------------------------------------------------------------------------------------------------------------------------
{ This function is used for preserving more than 4 decimal places on a bcd value. This
is needed because using AsCurrency or AsFloat seems to only preserve a maximum of 4... }
function CIL_ExtendedToBCD(ManyDecPlacesNum: Extended): TBcd;
begin
{ Will return a number with up to 123456789.1234567890... }
Result := VarToBCD(VarFmtBCDCreate(ManyDecPlacesNum,19,10));
end;
{ Used for assigning the value to the clientdataset... }
cdsInvDetailUNIT_CHARGE.AsBcd := CIL_ExtendedToBCD(Unit_Charge);
-------------------------------------------------------------------------------------------------------------------------------------------------
After inspecting this value after a POST this value was still correct on the TClientDataSet. However after using ApplyUpdates on the TClientDataSet the value is only save as 4 decimal places in the SQL Server table.
eg
47.143433434 (in the Client Dataset TFMTBCDField field prior to ApplyUpdates)
but stored as 47.1434 in the SQL Server 2000 table
Is this a known problem? Are there any work arounds?
Thanks for your help.
Stefan Fiorentini
I'm currently using the dbExpress driver for MS SQL Server 2.00 with Delphi v6.
I'm trying to save a decimal value with more that 4 decimal places to a SQL Server 2000 table.
The field is declared as
Unit_Charge DECIMAL 19,10
in the SQL Server 2000 table.
I can seem to successfully get the value of the Unit_Charge into the TClientdataset with more than 4 decimal places by
using aABcd when assigning the value (and using variants to successfully convert from EXTENDED to BCD)
eg
-------------------------------------------------------------------------------------------------------------------------------------------------
{ This function is used for preserving more than 4 decimal places on a bcd value. This
is needed because using AsCurrency or AsFloat seems to only preserve a maximum of 4... }
function CIL_ExtendedToBCD(ManyDecPlacesNum: Extended): TBcd;
begin
{ Will return a number with up to 123456789.1234567890... }
Result := VarToBCD(VarFmtBCDCreate(ManyDecPlacesNum,19,10));
end;
{ Used for assigning the value to the clientdataset... }
cdsInvDetailUNIT_CHARGE.AsBcd := CIL_ExtendedToBCD(Unit_Charge);
-------------------------------------------------------------------------------------------------------------------------------------------------
After inspecting this value after a POST this value was still correct on the TClientDataSet. However after using ApplyUpdates on the TClientDataSet the value is only save as 4 decimal places in the SQL Server table.
eg
47.143433434 (in the Client Dataset TFMTBCDField field prior to ApplyUpdates)
but stored as 47.1434 in the SQL Server 2000 table
Is this a known problem? Are there any work arounds?
Thanks for your help.
Stefan Fiorentini