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

SUM with IIF incorrectly rounding when expecting 2 decimals

2 Answers 414 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Kerry
Top achievements
Rank 1
Kerry asked on 19 May 2012, 05:00 AM
I've found an issue where if you have a textbox using an expression

 Sum(IIF(Fields.typeCode="DG",Fields.TotalAmount,0))  will round your result up or down regardless of the Format of the control,  when I change it to ....Sum(IIF(Fields.typeCode="DG",Fields.TotalAmount,0.00)) the results are NOT rounded.

To recreate this you must ensure the the first record in your result set causes the IIF condition evaluates to the false-part first meaning it will sum the 0.  I'm assume the report engine processes the "0" and automatically defaults the number of decimals to match the format of 0....if the engine encounters 0.00 it auto formats to use 2 decimal places. You will not see this behavior if the IIF evaluates the true-part first with existing decimal data.  Using Telerik Reporting ver 6.0.12.215

Thanks,

Kerry 

2 Answers, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 21 May 2012, 01:30 PM
Hello Kerry,

Check the following forum thread for explanation on this behavior: Sum function round to zero decimal places.

Greetings,
Steve
the Telerik team

BLOGGERS WANTED! Write a review about Telerik Reporting or the new Report Designer, post it on your blog and get a complimentary license for Telerik Reporting. We’ll even promote your blog and help bring you a few fresh readers. Yes, it’s that simple. And it’s free. Get started today >

0
derek
Top achievements
Rank 1
answered on 28 Dec 2012, 03:33 PM
Thank you so much.  From looking at the problem I was having I thought "This makes no sense", but after looking at your post I realized that the "0" was the problem.  The Fields.Amount is a decimal variable, but 0 is an integer, so the returned value in either piece is an integer (the lowest common denominator of decimal and integer) -- or at least that sort of thing.  So changing my expressions to 0.00 did what I wanted/expected.

I didn't follow through to the other posts.  I don't even think I finished reading the original post but it solved my problem, so thank you.
Tags
General Discussions
Asked by
Kerry
Top achievements
Rank 1
Answers by
Steve
Telerik team
derek
Top achievements
Rank 1
Share this question
or