How to get system currency symbol to a string

2019-04-08 18:47发布

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

3条回答
叛逆
2楼-- · 2019-04-08 18:51

You can use:

System.Globalization.CultureInfo.CurrentCulture.NumberFormat.CurrencySymbol;
查看更多
Summer. ? 凉城
3楼-- · 2019-04-08 18:56

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
查看更多
Root(大扎)
4楼-- · 2019-04-08 18:57

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

Console.Write(System.Threading.Thread.CurrentThread.CurrentCulture.NumberFormat.CurrencySymbol)
查看更多
登录 后发表回答