title: Formatting GridView values based on decimals
body: <p>I want to check all the values of a gridview and if there is no decimals I want to show only the integer part of the value, else if there is any decimals I want to show only two decimals. I use this but nothing...     </p>
  
  <pre><code>protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
  {
      for (int i = 0; i &lt; e.Row.Cells.Count; i++)
      {
          var p = Convert.ToDouble(e.Row.Cells[i].Text);
          e.Row.Cells[i].Text = String.Format("{0:0.##}", p);
      }                 
      }
  </code></pre>
  
  <p>example: if a value is 3.6666666 I want to show 3.66 and
  if a value is 3.0000000 I want to show 3. Also If a Value is string do nothing.
  Any suggestions?</p>
  
  <p>I did it with asp code:</p>
  
  <pre><code>&lt;asp:TemplateField HeaderText="3P" SortExpression="3POINT_MADE"&gt;
                  &lt;ItemTemplate&gt;
                      &lt;asp:Label ID="Label3" runat="server" Text='&lt;%# Eval("3POINT_MADE", "{0:0.##}") + "/" + Eval("3POINT_ATTEMPT", "{0:0.##}") %&gt;'&gt;&lt;/asp:Label&gt;
                  &lt;/ItemTemplate&gt;
              &lt;/asp:TemplateField&gt;
              &lt;asp:BoundField DataField="DEFENSIVE_REBOUNDS"  DataFormatString="{0:0.##}" HeaderText="DR" SortExpression="DEFENSIVE_REBOUNDS" /&gt;
  </code></pre>
  
  <p>Is there any suggestion to do it with c# in behind code? I think that is better and has better performance.</p>