I have a TDBEdit
connected to a TFloatField
which has DisplayFormat = '0.################'
.
I've set the field's value to 12.123456789
and I've noticed that my edit control displays it as '12,1234567890000005'
.
I don't have a deep knowledge about floating point numbers but I know that this happens because floating point numbers are approximated.
Anyhow, I'm wondering how can I make sure that additional decimals will never "magically" appear after the user types a value?
I thought to shorten the DisplayFormat
string by removing one '#'
but I don't know if this would be sufficient to avoid the problem in any condition.
Example:
uses
DBClient, DB, DBCtrls;
...
var
Dst : TClientDataSet;
Dsc : TDataSource;
Fld : TFloatField;
Edit : TDBEdit;
begin
//components creation
Dst := TClientDataSet.Create(Application);
Dst.FieldDefs.Add('TEST', ftFloat, 0, False);
Dst.CreateDataSet();
Fld := Dst.Fields[0] as TFloatField;
Fld.DisplayFormat := '0.################';
Dsc := TDataSource.Create(Application);
Dsc.DataSet := Dst;
Edit := TDBEdit.Create(Application);
Edit.DataSource := Dsc;
Edit.DataField := Fld.FieldName;
Edit.Align := alTop;
Edit.Parent := Self;
//test
Dst.Open();
Dst.Append();
Fld.AsFloat := 12.123456789;
Dst.Post();