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

编程入门 行业动态 更新时间:2024-10-23 03:33:30
本文介绍了在Delphi中,如何使货币数据类型以不同的货币以不同的形式显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我需要编写一个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中,如何使货币数据类型以不同的货币以不同的形式显示?

本文发布于:2023-07-18 04:38:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1141090.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:货币   数据类型   形式   Delphi

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!