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

Summary Row incorrect value on SUM

3 Answers 82 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Shaun
Top achievements
Rank 1
Shaun asked on 26 Sep 2013, 04:14 AM
Hi,

I have a gridView with a bunch of columns and a bottom summary row which also has a bunch of SUM columns.
One of my columns, "volume" has 2 decimal places but the summary row seems to be rounding the values therefore gives an incorrect value.

I have formatted the summary to show 2 decimal places, which is does but the SUM calculation is still incorrect.

To test this I added an export to excel function so that I could use Excel to double check the total SUM of the Volume column and this does show that the Grid summary is incorrect.

I know I must be missing something obvious but I cannot see it.

Thanks for your help.

Cheers
Shaun.

3 Answers, 1 is accepted

Sort by
0
Shaun
Top achievements
Rank 1
answered on 26 Sep 2013, 04:44 AM
Hi,

I managed to fix this by changing "Volume" to a double from a float within my class.

The grid now calculates correctly, but I still find it a bit odd that all the values within the grid displayed OK but the SUM value is / was incorrect.

Cheers

Shaun
0
Dimitar
Telerik team
answered on 30 Sep 2013, 04:20 PM
Hi Shaun,

Thank you for contacting Telerik support.

Sometimes abnormalities can be observed when using floating-point numbers. For example you can take a look at the following discussions:c# - Floating point operations ambiguity or Why is floating point arithmetic in C# imprecise? 

What I can recommend you, especially if you have financial calculations in you project is to use the decimal floating-point real number type in C#.  Some of the advantages of this type are:
  • No round-off errors
  • Almost no loss of precision

Please let me know if there is something else I can help you with.

Regards,
Dimitar
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Shaun
Top achievements
Rank 1
answered on 03 Oct 2013, 09:26 PM
Hi Dimitar,

Thanks for getting back to me, I'll check out your links.

Cheers

Shaun.
Tags
GridView
Asked by
Shaun
Top achievements
Rank 1
Answers by
Shaun
Top achievements
Rank 1
Dimitar
Telerik team
Share this question
or