How to get system currency symbol to a string

非 Y 不嫁゛ 提交于 2020-01-13 02:52:28

问题


If I do this:

Console.Write("The sum is {0:c}", 12);

I'm on a Swedish computer so it'll return: The sum is 12,00 kr

But is there a simple way of getting just the currency symbol, without a number? Like this (obviously this doesn't work, but just to show what I'm after):

 Console.Write("The symbol is {c}");

I would like that to output: The symbol is kr


回答1:


This code should return the currency symbol you're looking for.

System.Globalization.RegionInfo.CurrentRegion.CurrencySymbol

You could also use the following instead to get the ISO currency symbol

System.Globalization.RegionInfo.CurrentRegion.ISOCurrencySymbol



回答2:


You can use:

System.Globalization.CultureInfo.CurrentCulture.NumberFormat.CurrencySymbol;



回答3:


You can get it off of the NumberFormat in the CurrentCulture:

Console.Write(System.Threading.Thread.CurrentThread.CurrentCulture.NumberFormat.CurrencySymbol)


来源:https://stackoverflow.com/questions/11363250/how-to-get-system-currency-symbol-to-a-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!