tags:

views:

233

answers:

3

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)

+2  A: 

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);

C Harmon
+4  A: 

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 := '';
François
But I'm trying to format the Value that will be a currency, not the value that will be set with CurrToStrF - how can I change the currency value to not display the currency symbol?
croceldon
Not sure I understand... The currency symbol is not linked to a currency value but to a FormatSettings, either the default one used by default when not otherwise specified or a specific one like your `langFormat.CurrencyString`. So if your Value is a Currency, it will stay a Currency but will be displayed by default according to the global CurrencyString. If you change it from '$' to '@', your Value will then be displayed like @12.34 instead of $12.34 like before.
François
A: 

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;