Home General
New Blog Posts: Merging Reports - Part 1 and Part 2

Currency Formats

edited November 2012 in General
Hi,

I am trying to display currency amounts in my app with appropriate
currency symbols (£, $, € etc). In most situations I can accomplish
this by changing a field's DisplayFormat prior to it printing but
(perversly) I cannot show a $ symbol (I'm in the UK so my locale is set
to £). I've figured that this is because TppDisplayFormat.Format uses
the $ symbol as a currency indicator which it then replaces with the
local currency, so how do I get a $! I've tried preceeding it with a \,
but this just produces \£.

I guess I could create a descendant of TppDisplayFormat and use the £
symbol as the "soft" currency indicator but then I'm left with the issue
that I've got to work through the 100 or so exiting reports swapping $'s
for £'s... Also I can't figure out how to make this work at design
time.

Regards

Steve Everington

Comments

  • edited November 2012
    On 23/11/2012 17:38, Steve Everington wrote:

    This is how I do it.....


    TnavDisplayFormat = class(TppDisplayFormat)
    private
    class var
    public
    // this extension of the RB formatting class overcomes assumptions in
    RB code that '$' symbol represents global CurrencyString
    class function Format(const aDisplayFormat : String; aDataType :
    TppDataType; aValue : Variant) : String; override;
    class procedure GetDisplayFormats(aDataType : TppDataType;
    aFormatList : TStrings); override;
    end;


    .........

    class function TnavDisplayFormat.Format(const aDisplayFormat : String;
    aDataType : TppDataType; aValue : Variant) : String;
    var lCurrency : Byte;
    begin
    result := inherited Format(aDisplayFormat, aDataType, aValue);

    if VarIsNull(aValue) then
    Exit;

    if (aDisplayFormat <> '') then
    if aDataType in [dtCurrency, dtSingle, dtDouble, dtExtended] then
    begin

    case aDataType of
    dtCurrency :
    begin

    if aDisplayFormat =
    CurrencyManager.CurrencySet[0].CurrencyFomattingstring then
    lCurrency := 0 else
    if aDisplayFormat =
    CurrencyManager.CurrencySet[1].CurrencyFomattingstring then
    lCurrency := 1 else
    if aDisplayFormat =
    CurrencyManager.CurrencySet[2].CurrencyFomattingstring then
    lCurrency := 2 else
    if aDisplayFormat =
    CurrencyManager.CurrencySet[3].CurrencyFomattingstring then
    lCurrency := 3;


    DecimalSeparator :=
    CurrencyManager.CurrencySet[lCurrency].DecimalSeparator;
    ThousandSeparator :=
    CurrencyManager.CurrencySet[lCurrency].ThousandSeparator;

    ppFormatSettings.DecimalSeparator := DecimalSeparator;
    ppFormatSettings.ThousandSeparator := ThousandSeparator;

    Result := FormatCurr(aDisplayFormat, aValue);

    end;

    dtSingle,
    dtDouble,
    dtExtended :
    begin
    if aDisplayFormat =
    CurrencyManager.CurrencySet[0].DecimalFomattingstring then
    lCurrency := 0 else
    if aDisplayFormat =
    CurrencyManager.CurrencySet[1].DecimalFomattingstring then
    lCurrency := 1 else
    if aDisplayFormat =
    CurrencyManager.CurrencySet[2].DecimalFomattingstring then
    lCurrency := 2 else
    if aDisplayFormat =
    CurrencyManager.CurrencySet[3].DecimalFomattingstring then
    lCurrency := 3;

    DecimalSeparator :=
    CurrencyManager.CurrencySet[lCurrency].DecimalSeparator;
    ThousandSeparator :=
    CurrencyManager.CurrencySet[lCurrency].ThousandSeparator;

    ppFormatSettings.DecimalSeparator := DecimalSeparator;
    ppFormatSettings.ThousandSeparator := ThousandSeparator;

    Result := FormatFloat(aDisplayFormat, aValue);

    end;
    end;

    end;
    end;
  • edited November 2012
    Hi Steve,

    Take a look at the following article on currency formatting in
    ReportBuilder. As Paul mentioned, one way to work around your issue is
    to create a simple TppDisplayFormat descendent that does the work for
    you. This would prevent the need to alter any of your existing reports.

    http://www.digital-metaphors.com/rbWiki/Design/Formatting/Currency_Formatting

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
This discussion has been closed.