Display currency in DBGrid

Posted on 2006-05-31
Last Modified: 2010-04-05
How can i display the values of field Price in DBGrid to a Currency? Can anybody give me a code? I do not want to use the onGetText(Sender: TField; var Text: String; DisplayText: Boolean);

By the way, the fieldtype of "Price" is Float.

Question by:girlswants_me

    Author Comment

    Thanks in advance.
    LVL 26

    Accepted Solution


    In the table/query/dataset, make sure the fields are added (right click, field editor, add all fields), then select the field and set the display format property to: $0,000.00

    You can also do this programmatically by getting the Field, casting as TNumericField, eg:




    Author Comment

    Where should i place the
    TFloatField(Table1.FieldByName('Price')).DisplayFormat:='$0,000.00'; ???

    Author Comment

    I got it!!! A million Thanks to you. I'll increase your points to 150 coz i'm very much happy with your genius answer.

    ps. my DBGrid doesn't auto adjust the field width whenever the value is 1,000,000.00. It covers a portion of the display, can you teach me how to make my DBGrid to auto adjust the width?

    Thank you very much!
    LVL 26

    Expert Comment

    by:Russell Libby

    You are very welcome....

    As to the second question; the float field will have a default display width based on 10 characters (the field's property DisplayWidth will be set to 10). To cover 1 million, formatted out as '$1,000,000.00' you should set the DisplayWidth to 13, or 14 to be on the safe side. This can be done either at design time (right click, field editor, add all fields, select field, update the displaywidth)  or at runtime, eg:

      with TFloatField(Table1.FieldByName('Price')) do

    You can also apply this value after the grid has loaded, and it will adjust itself to the newly changed value.

    As far as a true autosizing feature goes, this would require a lot more work; eg walking all column values and determing the output text length based on grid font and formatted size, then using the max length obtained and applying this to the grid column's width. If you need help with this, its probably better to open a new question.



    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
    Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now