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)
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 := '';
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);
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;
精彩评论