3

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 Answers 2

6

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

check this sample

TFloatField(YourDataSet.FieldByName('field')).DisplayFormat := '#,##0.00';
Sign up to request clarification or add additional context in comments.

2 Comments

Sure, but the event GetText gives more flexibility. For instance, you can use different masks is value is positive or negative.
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 docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/…
5

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.