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

Footer Aggregate - Average

5 Answers 243 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Philip Senechal
Top achievements
Rank 1
Philip Senechal asked on 15 Apr 2009, 10:27 PM
I can't seem how to figure out how to get correct decimal values in my footer aggregate using Avg as the aggregate method. Here is the column for the aggregate

<telerik:GridBoundColumn Aggregate="Avg" FooterAggregateFormatString="Avg: {0:0.00}" DataFormatString="{0:0}" HeaderText="Age" HeaderStyle-Wrap="false" UniqueName="age" DataField="age" SortExpression="age" Groupable="false"
    <ItemStyle Wrap="false" /> 
</telerik:GridBoundColumn> 

The values that are being averaged are 24, 10, 7, 14. The average comes out as 13.00 when it should come out as 13.75. If I change the FooterAggregateFormatString="Avg: {0:0.00}" to FooterAggregateFormatString="Avg: {0:0}", it rounds down to 13 instead of up to 14.

Can you tell me how to get an accurate average using this method. Thanks.


5 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 17 Apr 2009, 01:48 PM
Hi Philip,

I am sending you a small runnable application with the implementation request by you. Give it a try and let me know if you have other questions or problems.

Sincerely yours,
Pavlina
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Philip Senechal
Top achievements
Rank 1
answered on 22 Apr 2009, 09:31 PM
The example you sent me does the same thing...your average footer rounds to an integer.

You have unit prices of 263.5 and 123.79 that are averaging to 264 and 124 respectively. I need the averages to also be decimals. The average price of one unit that is 123.79 should be 123.79, not 124.

Is this possible? Thanks.
0
Philip Senechal
Top achievements
Rank 1
answered on 22 Apr 2009, 10:38 PM
I figured it out...the original data source is an integer since it can only be an integer. If I cast it to a decimal in the SQL statement, then the average comes out with decimal places. Interesting...I would have thought using DataType="System.Decimal" in the grid column would have allowed the aggregate to calculate the average properly.
0
Jonathan
Top achievements
Rank 1
answered on 02 Sep 2012, 05:08 AM
Moderators,

There was a server error when I tried to post and so there's a double-post. I'm editing the first one to ask you to delete it for me please. Thanks.

Regards,
Jonathan
0
Jonathan
Top achievements
Rank 1
answered on 02 Sep 2012, 05:10 AM
Hey Philip,

I know this is pretty far out, but I thought I'd share anyway for the benefit of the rest of the community:

The simpler way to accomplish this is to set the FooterAggregateFormatstring to "Average: {0:F}".

The "F" format specifier converts any text to a two decimal place float. That will automatically give you two decimal places with no rounding up or down to the nearest whole number. So there's no need to rejig your SQL. :)

Cheers,
Jonathan
Tags
Grid
Asked by
Philip Senechal
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Philip Senechal
Top achievements
Rank 1
Jonathan
Top achievements
Rank 1
Share this question
or