如何在 UWP 中获取当前用户的货币符号

How to get the currency symbol for current user in UWP

Microsoft 建议对 UWP 应用程序 (Use global-ready formats) 使用 Windows.Globalization 而不是 System.Globalization。

在 Windows.Globalization.NumberFormatting 命名空间下有一个 CurrencyFormatter Class 但我不想将数字格式化为货币。我想找到如何只获取货币符号。

在 UWP 中为当前用户返回货币符号的当前最佳做法是什么?

据我所知,没有直接的 属性 可以得到它,但是你可以使用这个小技巧:

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

您可以使用 NumberFormatInfo.CurrencySymbol 属性:

string currencySymbol = NumberFormatInfo.CurrentInfo.CurrencySymbol;