开发者

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)


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜