Subject Re: [firebird-support] float vs double precision
Author Geoff Worboys
Hi Kelly,

> 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?

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).

NOTE: 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.

Geoff Worboys
Telesis Computing