How to Format a DBGrid Column to Display Two Decimal Places? [duplicate]

感情迁移 提交于 2019-12-05 04:16:20

You can format the DBGrid columns by formatting the underlying fields. If not done, create static fields in your dataset and then set the DisplayFormat property of the field in question to 0.00 and you are done.

I use same method as Uwe answered, in code after opening the dataset just add this line of code to format certian column:

  TFloatField(MyDs.FieldByName('Cost')).DisplayFormat := '0.00';

You can format the field using the DrawDataCell event.

procedure TFormMain.DBGridCompareDrawDataCell(Sender: TObject;
  const Rect: TRect; Field: TField; State: TGridDrawState);
begin
  if Field.Name = 'FIELDNAME' then
    TFloatField(Field).DisplayFormat := '#,##0.00';
end;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!