How to get the currency symbol for current user in

2019-09-17 07:03发布

问题:

Microsoft recommends using Windows.Globalization rather than System.Globalization for UWP apps (Use global-ready formats).

Under Windows.Globalization.NumberFormatting Namespace there is a CurrencyFormatter Class but I do not want to format a number as currency. I want to find how to get the currency symbol only.

What is current best practice for returning the currency symbol for the current user in UWP?

回答1:

You can use the NumberFormatInfo.CurrencySymbol property for that:

string currencySymbol = NumberFormatInfo.CurrentInfo.CurrencySymbol;


回答2:

As far as I know there is no direct property to get that, but you can use this small trick:

var currencyInUse = new Windows.Globalization.GeographicRegion().CurrenciesInUse[0];
var currencyFormatter = new Windows.Globalization.NumberFormatting.CurrencyFormatter(currencyInUse) { IsDecimalPointAlwaysDisplayed = false, FractionDigits = 0 };
var currencySymbol = currencyFormatter.Format(0).Replace("0", "");