In my SalesOrder.dbf file I have 2 fields that are type float. One is Commission and the other is Price. The size for both fields are 6 with decimal as 2.
How do you specify the size and decimal count for these fields?
I would not touch the Size and Precision properties in the dbf FieldDefs because they behave in a counter-intuitive way.
- Size is the total count of characters before the decimal point, counted from the right, e.g. when Size=3 and the entered value is 1234, the DBF will store 234! When the Size is too small the format switches to exponential notation, like in your case.
- And Precision is not the number of decimal places, but the total number of digits: 1234.12345 is displayed as 1234.1 when Precision is 5, but 0.12345678 will become 0.12345 with the same precision.
Not sure if other dataset types behave in the same way.
Since you want a constant count of decimal places I would not recommend to change the default settings, i.e. add float fields only by Dbf1.AddFieldDefs(fieldname, ftFloat), no further specification.
The way to get two fixed decimal places is via the DisplayFormat and EditFormat of the field which you specify as '0.00' for two decimals. After opening the dbf add some code which iterates over the ftFloat fields, cast them to TFloatField and set the DisplayFormat/EditFormat:
Dbf1.Open;
for i := 0 to Dbf1.FieldCount-1 do
begin
if Dbf1.Fields[i] is TFloatField then
TFloatField(Dbf1.Fields[i]).DisplayFormat := '0.00';
end;