CRDBGrid formatting floats

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
StoneWeasel

CRDBGrid formatting floats

Post by StoneWeasel » Thu 10 Feb 2005 09:27

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?

Alex
Posts: 655
Joined: Mon 08 Nov 2004 08:39

Post by Alex » Thu 10 Feb 2005 10:46

Try to work with FloatFormat, FloatDigits and FloatPrecision properties of the desired Column. To understand how it works, pls. see help on FloatToStrF function.

StoneWeasel

Post by StoneWeasel » Thu 10 Feb 2005 10:52

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.

Alex
Posts: 655
Joined: Mon 08 Nov 2004 08:39

Post by Alex » Thu 10 Feb 2005 16:44

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.

Guest

Post by Guest » Thu 10 Feb 2005 17:12

Wonderful, thank you kindly for your help i should be fine now

kurt
Posts: 1
Joined: Wed 16 Jun 2010 13:02

Formating float fields

Post by kurt » Wed 16 Jun 2010 13:06

Thank you very much, i've been looking exactliy for this. Works great now!

Post Reply