我需要编写一个Delphi应用程序,该应用程序从数据库中的各个表中提取条目,并且不同的条目将具有不同的币种。因此,我需要为每种Currency数据类型($,Pounds,Euros等)显示不同的小数位数和货币字符,具体取决于我加载的商品的货币。
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.
有没有一种方法可以在几乎全局范围内更改货币,也就是说,对于以表格形式显示的所有Currency数据?
Is there a way to change the currency almost-globally, that is, for all Currency data shown in a form?
推荐答案即使使用相同的货币,也可能需要显示不同格式的值(例如,分隔符),所以我建议您将LOCALE而不是仅将货币与您的值相关联。 您可以使用简单的Integer来保存LCID(语言环境ID)。 请在此处查看列表: msdn.microsoft/zh-cn/library/0h88fahh.aspx
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: msdn.microsoft/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;更多推荐
在Delphi中,如何使货币数据类型以不同的货币以不同的形式显示?
发布评论