croceldon
croceldon

Reputation: 4595

How to use Delphi's AsCurrency to show currency without currency symbol?

I'm trying to display a currency value in a grid, but I do not want the currency symbol to be shown:

if fPreferences.WorksheetFormat = 'Numeric' then
begin
  CurrencyString := '';
  Value := FieldByName('UnitList').AsCurrency;
end else
  Value := CurrToStrF(FieldByName('UnitList').AsCurrency, ffCurrency, 2, langFormat);

The problem is that it's still showing the currency symbol. What am I doing wrong here? I don't think I can use CurrToStrF, because I need the grid to export a number to excel, not a string. Or, is there any way I can use AsFloat, but have to decimal places? (100.00)

Upvotes: 3

Views: 6524

Answers (3)

Alfred Doppler
Alfred Doppler

Reputation: 68

a very simple solution would be to change the CurrencyString yourself and change it back to the original value later.

if fPreferences.WorksheetFormat = 'Numeric' then
begin
  CurrencyString := '';
  Value := FieldByName('UnitList').AsCurrency;
end else
  begin
    OldCurrStr := CurrencyString;
    CurrencyString := '';
    Value := CurrToStrF(FieldByName('UnitList').AsCurrency, ffCurrency, 2, langFormat);
    CurrencyString := OldCurrStr;
  end;

Upvotes: 0

Francesca
Francesca

Reputation: 21640

Doing CurrencyString := ''; will impact all the following formatting of currencies when using the default format strings and thus should display all the currency variants/fields values without the $ sign, while retaining their numeric nature.

But when you explicitly format your currency value with your own TFormatSettings langFormat, it has no effect unless you previously did:

langFormat.CurrencyString := '';

Upvotes: 4

C Harmon
C Harmon

Reputation: 208

Changing ffCurrency to ffFixed should get rid of the currency symbol but there wouldn't be any hundreds separators.

//With separators

sStrVar := FormatCurr('#,##0.00', CurrVar);

Upvotes: 2

Related Questions