Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the currency from current culture?

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

like image 433
YodasMyDad Avatar asked May 04 '10 06:05

YodasMyDad


3 Answers

Use the RegionInfo.ISOCurrencySymbol property. For example:

  var ri = new RegionInfo(System.Threading.Thread.CurrentThread.CurrentUICulture.LCID);
  Console.WriteLine(ri.ISOCurrencySymbol);

Output: "USD"

like image 148
Hans Passant Avatar answered Oct 20 '22 09:10

Hans Passant


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)

like image 44
Marc Gravell Avatar answered Oct 20 '22 08:10

Marc Gravell


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
like image 27
Fadrian Sudaman Avatar answered Oct 20 '22 10:10

Fadrian Sudaman