This is a migrated thread and some comments may be shown as answers.

Why GridCalculatedColumn does not display decimal numbers?

2 Answers 114 Views
Grid
This is a migrated thread and some comments may be shown as answers.
tomekm
Top achievements
Rank 1
tomekm asked on 22 Jun 2010, 12:33 PM

Why GridCalculatedColumn does not display decimal numbers?

<telerik:GridCalculatedColumn DataFields="CustomersActivated,Customers" Expression="({0}/{1})*100" DataType="System.Double" DataFormatString="{0:f}" telerik:GridCalculatedColumn/> 

For values like 1 and 300 grid displays "0.00" instead of "0.33"

2 Answers, 1 is accepted

Sort by
0
Accepted
Martin
Telerik team
answered on 22 Jun 2010, 04:59 PM
Hello Rychu,

I tried the following code and it ran as expected on my side:

Markup:

<telerik:RadScriptManager ID="RadScriptManager1" runat="server" />
<telerik:RadGrid ID="RadGrid1" runat="server" OnNeedDataSource="RadGrid1_NeedDataSource" AutoGenerateColumns="false">
    <MasterTableView>
        <Columns>
         <telerik:GridBoundColumn DataField="Numerator" HeaderText="Numerator" UniqueName="Numerator">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Denominator" HeaderText="Denominator" UniqueName="Denominator">
            </telerik:GridBoundColumn>
            <telerik:GridCalculatedColumn DataFields="Numerator,Denominator" Expression="({0}/{1})*100"
                DataType="System.Double" DataFormatString="{0:f}" HeaderText="Result">
            </telerik:GridCalculatedColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

Code behind:

protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
{
    DataTable table = new DataTable();
    table.Columns.Add("Numerator", typeof(double));
    table.Columns.Add("Denominator", typeof(int));
    for (int i = 0; i < 10; i++)
    {
        table.Rows.Add(i, (i*i)+1);
    }
    RadGrid1.DataSource = table;
}

I hope this helps,
Martin
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
tomekm
Top achievements
Rank 1
answered on 23 Jun 2010, 08:23 AM
Please close the ticket - my fault I did not cast int to double.
Tags
Grid
Asked by
tomekm
Top achievements
Rank 1
Answers by
Martin
Telerik team
tomekm
Top achievements
Rank 1
Share this question
or