如何在UWP中获取当前用户的货币符号
问题描述:
Microsoft建议对UWP应用程序使用Windows.Globalization而不是System.Globalization(Use global-ready formats)。如何在UWP中获取当前用户的货币符号
在Windows.Globalization.NumberFormatting命名空间下有一个CurrencyFormatter Class,但我不想将数字格式化为货币。我想找到如何获得货币符号。
当前在UWP中为当前用户返回货币符号的最佳做法是什么?
答
可以使用NumberFormatInfo.CurrencySymbol
属性为:
string currencySymbol = NumberFormatInfo.CurrentInfo.CurrencySymbol;
答
据我知道有没有直接的财产来获取,但你可以使用这个小窍门:
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", "");