title: Formating GridView to display whole number from decimal
body: <p>Code below contain representation of decimal nuber as whole but when I have 0.00 value in DB I need to show as 0 but in this format GridView is rendering empty value. I am accepting only whole number as input to DB (<em>decimalFromDB</em>). The reason whay it is decimal is b/c in the future we might have data with decimals for now I just want display as a whole number and when is 0.00 display 0.</p>
  
  <pre><code>    &lt;asp:BoundField DataField="decimalFromDB" HeaderText="Number" 
          SortExpression="Number" DataFormatString="{0:####}" 
          NullDisplayText="0" /&gt;
  </code></pre>
  
  <p>I am getting this error from Stack Track when tring DataFormatString="{0:d}" or {0:D}</p>
  
  <pre><code>[FormatException: Format specifier was invalid.]
     System.Number.FormatDecimal(Decimal value, String format, NumberFormatInfo info) +0
     System.Decimal.ToString(String format, IFormatProvider provider) +39
     System.Text.StringBuilder.AppendFormat(IFormatProvider provider, String format, Object[] args) +729
     System.String.Format(IFormatProvider provider, String format, Object[] args) +107
     System.Web.UI.WebControls.BoundField.FormatDataValue(Object dataValue, Boolean encode) +440
     System.Web.UI.WebControls.BoundField.OnDataBindField(Object sender, EventArgs e) +139
     System.Web.UI.Control.OnDataBinding(EventArgs e) +91
     System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +92
     System.Web.UI.Control.DataBind() +15
     System.Web.UI.Control.DataBindChildren() +201
     System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +101
     System.Web.UI.Control.DataBind() +15
     System.Web.UI.WebControls.GridView.CreateRow(Int32 rowIndex, Int32 dataSourceIndex, DataControlRowType rowType, DataControlRowState rowState, Boolean dataBind, Object dataItem, DataControlField[] fields, TableRowCollection rows, PagedDataSource pagedDataSource) +166
     System.Web.UI.WebControls.GridView.CreateChildControls(IEnumerable dataSource, Boolean dataBinding) +3896
     System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data) +66
     System.Web.UI.WebControls.GridView.PerformDataBinding(IEnumerable data) +14
     System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) +128
     System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +33
     System.Web.UI.WebControls.DataBoundControl.PerformSelect() +143
     System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +74
     System.Web.UI.WebControls.GridView.DataBind() +4
     System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +66
     System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +75
     System.Web.UI.Control.EnsureChildControls() +102
     System.Web.UI.Control.PreRenderRecursiveInternal() +42
     System.Web.UI.Control.PreRenderRecursiveInternal() +175
     System.Web.UI.Control.PreRenderRecursiveInternal() +175
     System.Web.UI.Control.PreRenderRecursiveInternal() +175
     System.Web.UI.Control.PreRenderRecursiveInternal() +175
     System.Web.UI.Control.PreRenderRecursiveInternal() +175
     System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2496
  </code></pre>