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

Calculated Column with Decimals

3 Answers 103 Views
Grid
This is a migrated thread and some comments may be shown as answers.
TommyM
Top achievements
Rank 1
TommyM asked on 29 Nov 2008, 04:55 PM
I have a Calculated Grid Column that I am trying to use.  I have in the Expression property "{0}/{1}".  Both fields are of type int, but i want the calculated column to be of type double.  However, when the expression is calculated, the field returns 0.  Any thoughts?

<Columns> 
    <telerik:GridBoundColumn HeaderText="Name" DataField="PlayerName" /> 
    <telerik:GridBoundColumn HeaderText="GP" DataField="GamesPlayed" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" /> 
    <telerik:GridBoundColumn HeaderText="AB" DataField="AtBats" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" /> 
    <telerik:GridBoundColumn HeaderText="R" DataField="Runs" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" /> 
    <telerik:GridBoundColumn HeaderText="H" DataField="Hits" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" /> 
    <telerik:GridBoundColumn HeaderText="2B" DataField="Doubles" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" /> 
    <telerik:GridBoundColumn HeaderText="3B" DataField="Triples" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" /> 
    <telerik:GridBoundColumn HeaderText="HR" DataField="HomeRuns" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" /> 
    <telerik:GridBoundColumn HeaderText="RBI" DataField="RunsBattedIn" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" /> 
    <telerik:GridBoundColumn HeaderText="BB" DataField="Walks" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" /> 
    <telerik:GridBoundColumn HeaderText="HBP" DataField="HitByPitch" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" /> 
    <telerik:GridBoundColumn HeaderText="K" DataField="Strikeouts" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" /> 
    <telerik:GridBoundColumn HeaderText="SB" DataField="StolenBases" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" /> 
    <telerik:GridCalculatedColumn HeaderText="Avg" DataFields="AtBats,Hits" Expression="{1}/{0}" DataType="System.Double" DataFormatString="{0:N3}" /> 
</Columns> 

thanks in advance for your help.

Tommy Martin

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 01 Dec 2008, 12:18 PM
Hi TommyM,

Please refer the forum link which discuss similar scenario. You can try whether the CONVERT function is working fine for you.
GridCalculatedColumn

Thanks,
Princy.
0
TommyM
Top achievements
Rank 1
answered on 02 Dec 2008, 01:44 AM
Thanks for the reference.  However, I am having the same issue with the Convert method as the other developer in the article.

thanks,
0
TommyM
Top achievements
Rank 1
answered on 02 Dec 2008, 01:57 AM
Actually, I got it working using the following:  Expression='Double({1})/Double({0})

thanks again for your help.
Tags
Grid
Asked by
TommyM
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
TommyM
Top achievements
Rank 1
Share this question
or