How can I format decimal property to currency?
Below would also work, but you cannot put in the getter of a decimal property. The getter of a decimal property can only return a decimal, for which formatting does not apply.
decimal moneyvalue = 1921.39m;
string currencyValue = moneyvalue.ToString("C");
Properties can return anything they want to, but it's going to need to return the correct type.
private decimal _amount;
public string FormattedAmount
{
get { return string.Format("{0:C}", _amount); }
}
Question was asked... what if it was a nullable decimal.
private decimal? _amount;
public string FormattedAmount
{
get
{
return _amount == null ? "null" : string.Format("{0:C}", _amount.Value);
}
}
Try this;
string.Format(new CultureInfo("en-SG", false), "{0:c0}", 123423.083234);
It will convert 123423.083234 to $1,23,423 format.