gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 14:51:31 26 4
gpt4 key购买 nike

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

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

最佳答案

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

关于delphi - 在Delphi中,如何让货币数据类型以不同的形式以不同的货币显示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/86002/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com