How to get the currency symbol for current user in UWP

柔情痞子 提交于 2019-12-12 03:55:27

问题


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", "");


来源:https://stackoverflow.com/questions/42412937/how-to-get-the-currency-symbol-for-current-user-in-uwp

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