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