Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save gabrielgreen/2051997 to your computer and use it in GitHub Desktop.
Save gabrielgreen/2051997 to your computer and use it in GitHub Desktop.
Extend decimal type to return a formatted currency string
public static string ToCurrencyString(this decimal amount, string currency)
{
var map = new Dictionary<string, string>
{
{"USD", "en-us"},
{"GBP", "en-gb"},
{"EUR", "de-de"},
{"AUD", "en-AU"},
{"CAD", "en-us"}
};
if (!map.ContainsKey(currency))
throw new Exception("Unsupported currency: " + currency);
return string.Format(CultureInfo.CreateSpecificCulture(map[currency]), "{0:C}", amount);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment