Limit Decimal Places in DBGrid

2019-07-10 07:45发布

I have a DBGrid which is connected to a ClientDataSet and it has a field UnitCost. What I want to do is to limit to 2 decimal places every value that will be assigned to that field. Is there an easier way to do this other than validating every input value?

标签: delphi grid
3条回答
欢心
2楼-- · 2019-07-10 08:15
procedure TFMasterReport.DBDetail**DrawColumnCell**(Sender: TObject;
   const Rect: TRect; DataCol: Integer; Column: TColumn;
   State: TGridDrawState);
begin
    TFloatField(Tempdtl.FieldByName('TS_Rate')).DisplayFormat := '0.000';
    TFloatField(Tempdtl.FieldByName('TS_Tvol')).DisplayFormat := '0.00';
    TFloatField(Tempdtl.FieldByName('TS_permit')).DisplayFormat := '0.00';
    TFloatField(Tempdtl.FieldByName('TS_tax')).DisplayFormat := '0.00';
    TFloatField(Tempdtl.FieldByName('TS_nettval')).DisplayFormat := '0.00';
end;
查看更多
对你真心纯属浪费
3楼-- · 2019-07-10 08:19

You can try to set ClientDataset.FieldByName('UnitCost').EditMask := '#.00';

查看更多
虎瘦雄心在
4楼-- · 2019-07-10 08:30

I usually use:

TFloatField(Myds.FieldByName('MyField')).DisplayFormat := '#.##';

This should work with every type of TDataset

查看更多
登录 后发表回答