I want to format a decimal value as a currency value.
How can I do this?
By default, cells formatted as currency display two decimal places. You can change this setting so cells display as many decimal places as you type in them, or so all cells display the same number of decimal places.
United States (U.S.) currency is formatted with a decimal point (.) as a separator between the dollars and cents. Some countries use a comma (,) instead of a decimal to indicate that separation.
Press TAB, open the drop-down menu, and choose Number. Click in the Field Size property, open the drop-down menu, and choose Single. Press TAB, open the drop-down menu, and choose Fixed. Click in the Decimal Places property.
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); } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With