【问题标题】:In Delphi, how can you have currency data types shown in different currencies in different forms?在Delphi中,如何让货币数据类型以不同的形式以不同的货币显示?
【发布时间】:2008-09-17 18:10:52
【问题描述】:

我需要编写一个 Delphi 应用程序,从数据库中的各种表中提取条目,并且不同的条目将使用不同的货币。因此,我需要为每种货币数据类型(美元、英镑、欧元等)显示不同的小数位数和不同的货币字符,具体取决于我加载的项目的货币。

有没有一种方法可以几乎在全球范围内更改货币,即针对表单中显示的所有货币数据?

【问题讨论】:

    标签: delphi finance


    【解决方案1】:

    即使使用相同的货币,您也可能必须以不同的格式显示值(例如分隔符),因此我建议您将 LOCALE 而不是货币仅与您的值相关联。
    您可以使用简单的整数来保存 LCID(区域设置 ID)。
    在此处查看列表:http://msdn.microsoft.com/en-us/library/0h88fahh.aspx

    然后显示值,使用类似的东西:

    function CurrFormatFromLCID(const AValue: Currency; const LCID: Integer = LOCALE_SYSTEM_DEFAULT): string;
    var
      AFormatSettings: TFormatSettings;
    begin
      GetLocaleFormatSettings(LCID, AFormatSettings);
      Result := CurrToStrF(AValue, ffCurrency, AFormatSettings.CurrencyDecimals, AFormatSettings);
    end;
    
    function USCurrFormat(const AValue: Currency): string;
    begin
      Result := CurrFormatFromLCID(AValue, 1033); //1033 = US_LCID
    end;
    
    function FrenchCurrFormat(const AValue: Currency): string;
    begin
      Result := CurrFormatFromLCID(AValue, 1036); //1036 = French_LCID
    end;
    
    procedure TestIt;
    var
      val: Currency;
    begin
      val:=1234.56;
      ShowMessage('US: ' + USCurrFormat(val));
      ShowMessage('FR: ' + FrenchCurrFormat(val));
      ShowMessage('GB: ' + CurrFormatFromLCID(val, 2057)); // 2057 = GB_LCID
      ShowMessage('def: ' + CurrFormatFromLCID(val));
    end;
    

    【讨论】:

      【解决方案2】:

      我会使用 SysUtils.CurrToStr(Value: Currency; var FormatSettings: TFormatSettings): string;

      我会设置一个 TFormatSettings 数组,每个位置都配置为反映您的应用程序支持的每种货币。您需要为每个数组位置设置 TFormat 设置的以下字段:CurrencyString、CurrencyFormat、NegCurrFormat、ThousandSeparator、DecimalSeparator 和 CurrencyDecimals。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-09-24
        • 2017-01-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-04-23
        • 1970-01-01
        • 2015-10-24
        相关资源
        最近更新 更多