Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Crystal Report Roundup

Status
Not open for further replies.

patrandrews

Programmer
Nov 23, 2020
2
US
I am currently trying to use the RoundUp function in Crystal Report XI R2. 99% of the time it works fine but on occasion it is improperly rounding the value. The report as it is takes a string value, converts to a number, does some math, and then uses RoundUp.

If I put just the numbers in the formula it works fine:

RoundUp((.20 * 1.10), 2)

delivering the expected 0.22

But when using the field from the database:

RoundUp((.20 * val({Table.Field})), 2)

it comes back with 0.23.

The weird thing is that taking out RoundUp the value is .22. However when you expand the size of the field to 4 decimal places and put the Roundup back but to 3 places you get .221 which would explain the .23 if it wasn't coming up with the extra 0.001 from out of nowhere.

Any one come across this behavior before and know of a way to fix it. I could write a function and just bypass using RoundUp but I have apparently become fixated on figuring out why this is happening.

Thanks in advance
Patrick
 
Have you tried just doing a test formula with val({Table.Field}) and .20 * val({Table.Field}) to see what the numbers look like? I have not used Roundup before. So I tried some things with it and it worked as expected.
 
Thank you. I have but these were the results. I had started with all of the values and one by one added back in the different parts of the formula. Everything reported back as expected until I added in the roundup. I changed the precision and that was how I knew that it was adding to the decimal value in the roundup function causing it to round incorrectly. In the end I built a report function that did similar functionality. THanks for the assistance
 
Patrandrews--I played around with this, and was a little stunned to see how quirky/inconsistent the roundup() function was. I guessed that it must work by adding some small amount under certain conditions, but I was unable to determine the logic that was responsible for the errors.

If your report function works more accurately than roundup(), it might be valuable to share the code here, so others can benefit--either in a post or as an FAQ. Just a thought.

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top