views:

169

answers:

2

Hi

I need to format values in a DBGrid to display in a certain format ex '#,##0.00'. Any idea how to do that?

Regards, Pieter

+2  A: 

you can use the DisplayFormat property of the field to format.

check this sample

TFloatField(YourDataSet.FieldByName('field')).DisplayFormat := '#,##0.00';
RRUZ
Sure, but the event GetText gives more flexibility. For instance, you can use different masks is value is positive or negative.
Eduardo Mauro
If you need flexibility, but if not don't waste your time writing code for this. For the positive/negative example, if you read the documentation you will notice DisplayFormat support "sections" separated by semicolons, for positive, negative and zeros. So, you can use, for example: begin qOrdersTotal.DisplayFormat := ',0.00;(,0.00);Zero'; end;For more info read http://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/delphivclwin32/DB_TNumericField_DisplayFormat.html
jachguate
+2  A: 

Each Field in your DataSet has two events: OnGetText and OnSetText. Use event OnGetText of desired fields and use Format function to format the value using a mask.

Eduardo Mauro
Thanks Serg for the correction.
Eduardo Mauro