6

I am using a DBGrid component in Delphi. I wonder how I can set the format of a column. I have real values that I want to be displayed as currency in the grid.

Someone knows how?

Blue
  • 373
  • 2
  • 7
  • 16
  • possible duplicate of [How to Format a DBGrid Column to Display Two Decimal Places?](http://stackoverflow.com/questions/10271822/how-to-format-a-dbgrid-column-to-display-two-decimal-places) – neves Apr 11 '14 at 18:57

3 Answers3

9
  1. You can set the DisplayFormat of the Field
  2. You can handle OnGetText event. This approach allows to do more complex operations with the value.
horgh
  • 16,280
  • 18
  • 57
  • 114
5

If you don't add the fields to field Editor list you can get the formating by code as :

TFloatField(MyQuery.fieldByName('MyField').DisplayFormat := '0.00';

if you don't want to show the zeros replace '0.00' with '#.##';

Mohammed Nasman
  • 10,782
  • 7
  • 41
  • 67
2

The first port of call is the DisplayFormat of the data field in the database itself.

mj2008
  • 6,517
  • 2
  • 36
  • 53
  • I've set the column type to decimal(20,2) in my old MySql 4.1 database. Trailing zeros are not shown in the DBGrid. Is there something else to set? – Blue Oct 16 '08 at 14:29