Page 1 of 1

PRECISION IN DataSet TFloat fields

PostPosted: April 25th, 2009, 5:01 pm
by Johan Theunissen
How does one get the precision in a TFloat field of a DataSet set properly?

It does not seem to work when typecasting
i.e. TFloatField(XDataSet.FieldByName('CostPrice')).Precision:= 4;

All data in a data aware control such as TDBEdit will only work to a precision of 2 decimals so that any calculations based on that field will not have the neccesary accuracy, although the raw data in the underlying database will have full precision of double etc. data.

i.e. XDataSet.FieldByName('CostPrice').AsFloat:= 55.123456;
XDataSet.FieldByName('CostPrice').AsFloat * SomeNumber will not yield accurate answer to a higher precison than 2 because it seems that XDataSet.FieldByName('CostPrice').AsFloat in above calculation is used effectivly as 55.12.

Any answers please???

Re: PRECISION IN DataSet TFloat fields

PostPosted: May 10th, 2009, 1:12 pm
by Kambiz
Delphi gets precision of float fields from definition of table. You should set the precision when you create the tables.