Decimal Places in Grid

2 posts, 1 answers
  1. KawaUser
    KawaUser avatar
    58 posts
    Member since:
    Oct 2010

    Posted 09 Jun 2011 Link to this post

    I have a grid where I am showing a price field with 5 decimal places, but I only want to show decimal places when I need them.

    1,234.56000 >>> I would like to look like  >>>> 1,234.56

    Although in the same grid I could have >>>>> 0.98765

  2. Answer
    Martin avatar
    822 posts

    Posted 15 Jun 2011 Link to this post

    Hello Chuck,

    In RadGrid for ASP .NET AJAX you can easily achieve the desired output by supplying the correct format string in the column in question. Bellow is the code for a sample page that demonstrates this approach:

    <%@ Page Language="C#" %>
    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "">
    <head id="Head1" runat="server">
        <form id="mainForm" runat="server">
        <asp:ScriptManager runat="server" ID="ScriptManager1">
        <script type="text/C#" runat="server">
            protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
                System.Data.DataTable table = new System.Data.DataTable();
                table.Columns.Add("ID", typeof(int));
                table.Columns.Add("Number", typeof(decimal));
                table.Rows.Add(1, 1.25300);
                table.Rows.Add(2, 1.2555);
                table.Rows.Add(3, 1);
                table.Rows.Add(4, 1.2500);
                table.Rows.Add(5, 1.2000);
                table.Rows.Add(6, 1.25123);
                RadGrid1.DataSource = table;
        <telerik:RadGrid ID="RadGrid1" runat="server" OnNeedDataSource="RadGrid1_NeedDataSource"
                    <telerik:GridBoundColumn DataField="ID" HeaderText="ID">
                    <telerik:GridBoundColumn DataField="Number" HeaderText="Number" DataType="System.Decimal"
        <br />

    I hope this helps.

    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Back to Top