Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Field.DisplayFormat wrong approximation !

2 views
Skip to first unread message

Enrico Ghezzi

unread,
Jul 10, 2008, 10:51:20 AM7/10/08
to
Hi

i have a dbgrid with float field.

in the database there is : 7,895

i want 2 digit.

use this :

tblTabellaFieldFloat.DisplayFormat := '0,.##;-0,.##;0';

but the internal round is wrong.

Number 7,895 is viewed : 7,89

the correct is 7,90


WHY ?

John Herbster

unread,
Jul 10, 2008, 12:19:03 PM7/10/08
to
"Enrico Ghezzi" <Enrico...@Ghezzi.com> wrote

> I have a TDBGrid with float field.


> in the database there is : 7,895

Enrico,

A float (type double) field cannot hold 7,895 exactly.
If you try to assign '7.895' to a double you will get
+7.89499 99999 99999 57367 43585 43939 88847 73254 39453 125
which is closer to 7,89 than 7,90.

Is properly rounding (using DecimalRounding_JH1) your data
to two decimal fraction digits before you put it into the
data table possible?

If not, you could write an OnGetText event handler for the
field in question, and do the desired rounding there as you
format the values to text in that event handler.

Here is where you can find my DecimalRounding_JH1 module:
http://cc.codegear.com/Item/21909

HTH, JohnH

Justus J.

unread,
Jul 13, 2008, 5:06:19 PM7/13/08
to

Without any knowledge of the dbgrid or its features, I suspect the
displayformat is what it is : a format. It doesn't do a round, only a
trunc. Perhaps this can be tested with values 7,890 ... 7,899 : they
might ALL return '7,89'.

Justus

0 new messages