C# 给定货币代码格式化货币(如 USD / GBP / FRF)
我正在与返回货币 (System.Decimal
) 和货币代码的数据库集成。货币代码是诸如 "USD"
、"GBP"
甚至 "FRF"
之类的字符串。
mscorlib 是否有内置的东西可以帮助我格式化这些货币?我首先考虑在数据库货币代码和 CultureInfo
之间建立映射,但我不知道如何处理 FRF,因为如果我使用 "fr-FR"
,它将格式化为欧元而不是法郎。
我们必须支持的货币符号的完整列表是:
FRF
CHF
NZD
IN2
SAR
SEK
EUR
MXP
DKK
GBP
AUD
IN1
AED
CAD
NOK
INR
USD
PLN
I am integrating with a database which returns currencies (System.Decimal
) and currency codes. The currency codes are strings like "USD"
, "GBP"
, and even "FRF"
.
Is there something built-in to mscorlib which can help me format these currencies? I first thought about setting up a mapping between database currency code and CultureInfo
, but I don't know what to do about FRF because if I use "fr-FR"
, it would format as euros instead of francs.
The full list of currency symbols we must support is:
FRF
CHF
NZD
IN2
SAR
SEK
EUR
MXP
DKK
GBP
AUD
IN1
AED
CAD
NOK
INR
USD
PLN
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我会采用这种方法,但为 FRF 制作一个自定义
IFormatProvider
来执行您选择的格式。这就像正确构建 NumberFormatInfo 一样简单。I would take this approach, but make a custom
IFormatProvider
for FRF that does the formatting you choose. This is as easy as constructing a NumberFormatInfo properly.您可以替换默认货币并仍然使用该框架...
You can replace the default currency and still make use of the framework...
这是一个很小的清单。我只是手动设置映射。
That's a pretty small list. I'd just setup the mappings manually.