string.format currency code example

Example 1: how to format money as currency string

(12345.67).toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,');  // 12,345.67

Example 2: c# format decimal as currency

private decimal _amount;

public string FormattedAmount
{
    get { return string.Format("{0:C}", _amount); }
}

Example 3: c# format decimal as currency

private decimal? _amount;
// For nullable decimals
public string FormattedAmount
{
    get
    {
         return _amount == null ? "null" : string.Format("{0:C}", _amount.Value);
    }
}