在Delphi中,如何让货币数据类型以不同的形式以不同的货币显示?
我需要编写一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我会使用 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.
即使使用相同的货币,您也可能必须以不同的格式(例如分隔符)显示值,因此我建议您将 LOCALE 而不是仅与您的值关联的货币。
您可以使用简单的整数来保存 LCID(区域设置 ID)。
请参阅此处的列表:http://msdn.microsoft.com/en-us /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: http://msdn.microsoft.com/en-us/library/0h88fahh.aspx
Then to display the values, use something like: