bwc3068 wrote:

I've got 2 fields in a table:

Temperature Float
PartsCost Double Precision

In my Delphi application, I've got them persistent in a persistent query.

They are both tIBOFLoatField's and all their properties are the same (except the .Name and .FieldName).

In the form that uses these fields, I've got identical dbEdit controls who use these 2 fields.

IF I input "1.23" into the Double Precision field and then tab off of it, it reads: 1.23.

If I input "1.23" into the Float field and then tab off of it, it reads: 1.23000001907349

Any idea why the "float" field display incorrectly after the value get's placed into the query?

Again, all properties are identical on the edit and tIBOFloatField components. The only different is, in the SQL that creates the Firebird table (FB one is a "Float" and the other "Double Precision"?

Geoff Worboys answers:

The reason is fairly simple - Delphi is not very good with single ("float") data types. Many of it's function are not overloaded to single (or even double), instead the value is automatically cast up to extended with its supposed 18+ digits of significance.

FloatToStr is one such example, math.RoundTo and math.SimpleRoundTo are additional examples (as are RoundNear etc supplied with IBO).


Beware of math.SimpleRoundTo - I recently discovered that the implementation changed sometime between Delphi6 and Delphi2010 and it is no longer asymmetric as described in the supplied help files. I've written to Embarcadero but have not received any response.

You can work around the problem by implement specific to-str conversions that limit the output digits (which is usually a good idea anyway) but it is very difficult to prevent unwanted surprises arising from the use of single-precision fp.

My conclusion, from back in Delphi5 days and not changed since, is that the float/single data-type, which is never very useful, is pretty close to completely useless in Delphi. As a result things like percentages, which technically only "needed" float I have implemented as double anyway.

Like this post? Share on: TwitterFacebookEmail

Related Articles


Firebird Community



Gems from Firebird Support list