Page 1 of 1

CRDBGrid formatting floats

Posted: Thu 10 Feb 2005 09:27
by StoneWeasel
Hi there, i was just wondering if anyone new of a way of formating floats in the CRDBGrid componant so that they can be forced to show 2 decimal places. I have a price column in a grid you see and the client wants the prices to look like prices, i have tried to work this out but to no avail. anyone know how i can do this?

Posted: Thu 10 Feb 2005 10:46
by Alex
Try to work with FloatFormat, FloatDigits and FloatPrecision properties of the desired Column. To understand how it works, pls. see help on FloatToStrF function.

Posted: Thu 10 Feb 2005 10:52
by StoneWeasel
Thankyou for your incredably quick response, i should have mentioned in my previous post that i have looked at the FloatFormat, FloatDigits and FloatPrecision properties of the column and set them accordingly but this does not seem to affect the numbers displayed in the cells, i did notice in the help that this only affects the value shown in the status bar.
Am I doing something wrong or theoreticly should simply setting up these properties display the floats in the format i want?

Thank you kindly for your help.

Posted: Thu 10 Feb 2005 16:44
by Alex
Sorry for misunderstanding your post, actually settings for data values formatting placed in the field object, so you can access them by fields editor at design-time or with the next code at run-time:

Code: Select all

if OraQuery1.FieldByName('NUM') is TFloatField then
 (OraQuery1.FieldByName('NUM') as TFloatField).DisplayFormat := '0.##'
For more information see TFloatField Delphi help topic.

Posted: Thu 10 Feb 2005 17:12
by Guest
Wonderful, thank you kindly for your help i should be fine now

Formating float fields

Posted: Wed 16 Jun 2010 13:06
by kurt
Thank you very much, i've been looking exactliy for this. Works great now!