Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I format decimal property to currency?

I want to format a decimal value as a currency value.

How can I do this?

like image 987
WingMan20-10 Avatar asked Aug 13 '10 17:08

WingMan20-10


People also ask

How many decimal places do I use when changing to currency?

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.

What format is used for dollar amounts?

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.

How do you change decimal places in access?

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.


1 Answers

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);     } }   
like image 90
Robaticus Avatar answered Oct 06 '22 12:10

Robaticus