在Delphi中,如何让货币数据类型以不同的形式以不同的货币显示?

发布于 2024-07-04 09:24:22 字数 162 浏览 6 评论 0原文

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

有没有一种方法可以几乎全局地更改货币,即对于表单中显示的所有货币数据?

I need to write a Delphi application that pulls entries up from various tables in a database, and different entries will be in different currencies. Thus, I need to show a different number of decimal places and a different currency character for every Currency data type ($, Pounds, Euros, etc) depending on the currency of the item I've loaded.

Is there a way to change the currency almost-globally, that is, for all Currency data shown in a form?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ゝ杯具 2024-07-11 09:24:22

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

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

I'd use SysUtils.CurrToStr(Value: Currency; var FormatSettings: TFormatSettings): string;

I'd setup an array of TFormatSettings, each position configured to reflect each currency your application supports. You'll need to set the following fields of the TFormat Settings for each array position: CurrencyString, CurrencyFormat, NegCurrFormat, ThousandSeparator, DecimalSeparator and CurrencyDecimals.

思念满溢 2024-07-11 09:24:22

即使使用相同的货币,您也可能必须以不同的格式(例如分隔符)显示值,因此我建议您将 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;

Even with the same currency, you may have to display values with a different format (separators for instance), so I would recommend that you associate a LOCALE instead of the currency only with your values.
You can use a simple Integer to hold the LCID (locale ID).
See the list here: http://msdn.microsoft.com/en-us/library/0h88fahh.aspx

Then to display the values, use something like:

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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文