Created
March 16, 2012 19:25
-
-
Save gabrielgreen/2051997 to your computer and use it in GitHub Desktop.
Extend decimal type to return a formatted currency string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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