Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Rounding sums and affect on formula Post Reply Post New Topic
Author Message
spl1
Newbie
Newbie
Avatar

Joined: 18 Jun 2009
Location: United Kingdom
Online Status: Offline
Posts: 20
Quote spl1 Replybullet Topic: Rounding sums and affect on formula
     Posted: 19 Jun 2009 at 4:22am
Hi
I have created a main report which brings back data from database as 0.000 decimal places, of which I have then rounded up to 0.00 places for currency. However the sum of the formula per group does not balance to what has been given once the rounding has been placed on it.
I have tried placing a sum(field,group) formula and then round it but it still gives the wrong result
 
In essence I want to add together the rounded results at group level
 
Help please....
Many thanks
Sarah
 
Sarah
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 19 Jun 2009 at 6:41am
rounding at different levels is always a crap shoot.  Because if you have 2 items .053 in the details they will round to .05, but when you add them you get .11.  My suggestion would be a variable, shared of course, that is incremented with the rounded value, so the .05 and .05 will display as .10.
 
Since this is being done at the group level, remember to reset the variable to 0 when the group changes...you might need to update another variable if you want subtotals in larger groups or for the report.
 
HTH
 
IP IP Logged
spl1
Newbie
Newbie
Avatar

Joined: 18 Jun 2009
Location: United Kingdom
Online Status: Offline
Posts: 20
Quote spl1 Replybullet Posted: 19 Jun 2009 at 11:20am

Thank you

But still new to sharedvariables - so my main formula is:-
//basic
sum(field,group)   answer £131.664
 
then when i've rounded i've used
//basic sum
round((basic),2)   answer £131.66
 
So, how would i create the shared variable
 
Thank you in advance - think i'll get lots of practice of shared variables on this report as i have 4 formulas that i need to account for and then the line subtotals and 3 group totals LOL

Sarah
Sarah
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 22 Jun 2009 at 6:19am

group header:

shared numbervar gTotal :=0;
""//to hide the result
 
details
shared numbervar gTotal := gTotal + round({table.field},2);
 
round({table.field},2)  //displays the rounded value for the report
 
group footer
shared numbervar gTotal
 
If needed addition varibles can be updated in any/all of the formulas.  I frequently in the group footer formula do something like:
shared numbervar gTotal;
shared numbervar gTotal1:=gTotal1 + gTotal;
gTotal
 
this will increment the next level of variables.
 
HTH
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum