Is there a way to get current information dynamically from the apps culture settings? Basically if the user has set the culture to US I want to know the currency is dollars, or if they have it set to UK I want to pound sterling etc... etc..
This is so I can send this information to PayPal when a payment is being made
Use the RegionInfo.ISOCurrencySymbol property. For example:
var ri = new RegionInfo(System.Threading.Thread.CurrentThread.CurrentUICulture.LCID);
Console.WriteLine(ri.ISOCurrencySymbol);
Output: "USD"
You can get the symbol from CultureInfo.CurrentCulture.NumberFormat.CurrencySymbol
, but I doubt this is enough; you may need to maintain a separate list per culture. Or just let the user tell you what they want to pay in (for example, they might be away from home, etc, so the culture of the PC in some hotel lounge isn't what is on their credit card)
Once you have the CultureInfo ci object, you can ask such as
ci.NumberFormat.CurrencySymbol
For current culture, you will simply do
CultureInfo.CurrentCulture.NumberFormat.CurrencySymbol
string isoCurrencySymbol = RegionInfo.CurrentRegion.ISOCurrencySymbol;
You can basically use CultureInfo class
CultureInfo ci = new CultureInfo(UICulture);
var symbol = ci.NumberFormat.CurrencySymbol;
public static string GetCurrencySymbol(string currency)
{
if (currency == null) return "";
if (currency == "") return "";
int i = 0;
var regionInfo = new RegionInfo(System.Threading.Thread.CurrentThread.CurrentUICulture.LCID);
foreach (var cultureInfo in CultureInfo.GetCultures(CultureTypes.AllCultures & ~CultureTypes.NeutralCultures))
{
if (!cultureInfo.Equals(CultureInfo.InvariantCulture))
{
var regionCulture = new RegionInfo(cultureInfo.LCID);
if(regionCulture.ISOCurrencySymbol == currency)
{
//list.Add(regionCulture);
regionInfo = regionCulture;
}
}
}
http://help.outlook.com/en-us/140/system.globalization.regioninfo.currencynativename(VS.85).aspx
You'll want the RegionInfo.CurrencyNativeName, RegionInfo.CurrencyEnglishName or RegionInfo.ISOCurrencySymbol
来源:https://stackoverflow.com/questions/2763128/get-the-currency-from-current-culture