Home DADE

Format function not working

edited October 2004 in DADE
I use RB 7.04 Pro and I have a field that contains a float value.

I tried using FormatCurr and Format functions (Format('%f', data[field]);)
but the resulting string that is displayed is literally %f and not the
formatted value.

Am I doing something wrong?

Thank you,

Peter V

Comments

  • edited October 2004

    Not sure I understand the question.

    1. Are you trying to use the Query Designer's Calc tab to create a
    calculated field for the query that has formatting. If so then you need to
    use whatever functions your sql server product supports.

    2. The standard approach is let the query build the result set containing
    the numeric values, then use TppDBText.DisplayFormat property to specify the
    format for display on the report. Right-click over the DBText and select
    DisplayFormat and a list of relevant formats for the datatype will be
    displayed. You can also type in additional formats. Internally ReportBuilder
    uses Delphi's FloatToStrF. See ppDisplayFormat.pas. You can easily create a
    descendant of TppDisplayFormat and specify that your TmyDisplayFormat be
    used by ReportBuilder to perform formatting. See the initialization section
    ppDisplayFormat.pas.






    --
    Nard Moseley
    Digital Metaphors Corporation
    www.digital-metaphors.com



    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
  • edited October 2004
    I think I may have posted in the wrong group, sorry.

    The problem basically is that a query returns a float value which I would
    like to format to a string according to my needs.

    So in the report's "Calc" section in the OnCalc event I have placed this:

    if [field] = 0 then
    Value := 'Blank'
    else
    Value := Format('%f, [field]);

    But in preview I can see this:

    rec1 Blank
    rec2 Blank
    rec3 %f
    rec3 Blank
    rec4 %f
    etc ...

    What I would like to see is this:

    rec1 Blank
    rec2 Blank
    rec3 65.88
    rec3 Blank
    rec4 78.99
    etc ...

    I also tried the FormatCurr function but the result is the same.

    Thank you for your help.


  • edited October 2004

    For future reference, questions about using the Calc workspace should be
    posted to the RAP newsgroupt. (questions about using the Data workspace can
    be posted to the DADE newsgroup. )

    The functions found in the CodeToolbox correspond to Delphi functions. To
    use FormatFloat or FormatCurr, check out the Delphi help.

    Here is an example that works in my testing here:


    if customer['TaxRate'] = 0 then
    Value := 'Blank'
    else
    Value := FormatFloat('#,0.00;-#,0.00', customer['TaxRate']);


    --
    Nard Moseley
    Digital Metaphors Corporation
    www.digital-metaphors.com



    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
  • edited October 2004
    That worked, thank you very much for your help.


This discussion has been closed.