Home General
New Blog Posts: Merging Reports - Part 1 and Part 2

Sum rounding problem.

edited October 2005 in General
I have a report that sums smallmoney data fields incorrectly.

I use $#,0.00;-$#,0.00 as the display format for all

Actual Values Displayed Values
============= ================
85.1875 85.19
88.125 88.13
188.00 188.00
117.50 117.50
23.50 23.50
------------- ----------------
502.3125 actual sum 502.32
displayed sum 502.31

So the sum is correct for the actual field values but the
rounding of the field values gives a discrepancy. In fact its
all correct. All the rounding is correct the problem is that the
sum rounds the total whilst what I need is a total of the
rounded values.

I guess I need to round the original data but at what point? I
could use variables instead and round them but then I'd need to
do all the sums too. OK but could I not use something like
OnGetText? Would sum work on the raw values still though?

Pat Bell

Comments

  • edited October 2005
    Hi Pat,


    Unfortunately not. The DBCalc component does not interact with a DBText
    component at all when calculating a sum, it pulls the valued directly off
    the database. My recomendation would be to place a TppVariable in place of
    the DBCalc (making it calc on Traversal) and inside it's OnCalc event, round
    and sum the database values manually. (The DBText component can remain as
    it seems to be functioning correctly).

    --
    Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited February 2009
    Has anyone got an example of how to do the rounding in RAP? I'm trying
    to round to 2 places and sum up a column of numbers as described in the
    original post. ROUNDTO isn't supported so it's either round or trunc
    functions.

    Something like the following should work but doesn't

    x := trunc((x * 100) + 0.5) / 100

    Jon Gray
  • edited February 2009
    This appears to do the correct 'non-banker' rounding coupled with the
    correct traversal and reset on the variables.

    Result := int((x*100)+0.5) / 100;


  • edited February 2009
    Hi Jon,

    Another option would be to create a pass-thru function for the RoundTo
    routine. Examples of creating pass-thru functions can be found in the
    \Demos\0. RAP\... directory.

    --
    Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
This discussion has been closed.