Skip to content

Instantly share code, notes, and snippets.

@weiland
Last active August 29, 2015 14:15
Show Gist options
  • Save weiland/b7698548509e6b9c08cf to your computer and use it in GitHub Desktop.
Save weiland/b7698548509e6b9c08cf to your computer and use it in GitHub Desktop.
C# Model: Dealing with Currency
private string _articlePrice;
public string ArticlePrice {
get
{
return _articlePrice;
}
set
{
Thread.CurrentThread.CurrentCulture = new CultureInfo("de");
_articlePrice = String.Format("{0:C}", decimal.Parse(value));
}
}
// will output a nice 42,00€ instead of 42.00000
// the CultureInfo can be changed to a different country and
// one can manually change the currency symbol
// Second approach which prevents converting errors
// Basically, you set the ArticlePriceDecimal which accepts a decimal value
// and you get the lang converted price as string via ArticlePrice
private string _articlePrice;
public decimal ArticlePriceDecimal
{
set
{
Thread.CurrentThread.CurrentCulture = new CultureInfo("de");
_articlePrice = String.Format("{0:C}", value);
}
}
public string ArticlePrice {
get
{
return _articlePrice;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment