• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 919
  • Last Modified:

Always round fractions of a cent up!! general math issues with Crystal reports .net 9

Im using Crystal Reports 9 bundled iwth visual studio .net 2003 and i constantly lose pennies whenever it performs addition or multiplication operations of any magnitude, these add up over the course of the invoice Im creating.  seriously, it can take 150.30 * 6 and get 900.15 where the heck did the other 3 cents go.  Im confused.  Please help.  Ive tried truncation and a number of different things and nothing seems to work for me
0
mileyja
Asked:
mileyja
  • 4
  • 3
  • 2
2 Solutions
 
frodomanCommented:
My guess is that the number is actually 150.025 but you have the display field formatted in Crystal to only show 2 decimal places (which is the default format if you haven't changed it) so it's being seen in it's rounded form of 150.03 .  Format the field for 3 or 4 decimal places and see what the actual value in the field is.

frodoman
0
 
mileyjaAuthor Commented:
i meant 150.03, good call frodo, ill check on that and get back to you.  Gosh your quick!!
0
 
mileyjaAuthor Commented:
ok, your right there, it is 150.025 so what do I need for it to make that 150.03 and truncate it, even if it was 150.021 isnt it standard procedure to always round up with fractions of a percent??
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
gopatincCommented:
I understand you want to convert 150.026 to 150.03. To do that you can use the truncate function
ex: truncate(150.025,2)

This will truncate to 2 decimal points.
But this method will truncate 150.021 - 150.025 to 150.02 and from 150.026 -150.029 to 150.03

If you want 150.021 - 150.029 to be truncated to 150.03, then use the Ceiling function
ex: Ceiling(150.025,.01)

0
 
mileyjaAuthor Commented:
I think iwth money arent you supposed to go up to teh next cent with any remainder, I just want it to go the next cent if there is anything more than a whole cent at all.  I understood from teh good that the truncate function throws away the extra stuff without rounding at all.  The book could be wrong I guess Ill try that at work tommarow.  But I need a function that uses the same type rounding rules as normal accounting programs.
0
 
gopatincCommented:
Then u should use the Ceiling function I mentioned earlier.
0
 
frodomanCommented:
Ceiling is a database function though, it isn't supported in Crystal 9 as far as I know.  If you can select it from your db with the ceiling function that should work.  If not, create a formula in Crystal that will do the rounding for you - but if you want it to always round up you can't use the built-in round function so I'd use this formula:

  int(({table.field} * 100) + 0.9) / 100

The you can base your summary on this formula and it will add all of the rounded numbers.


0
 
mileyjaAuthor Commented:
well I wasnt sure what to do.  I figured out using what I had how to get the ceiling thing to work and that was part of the original question I asked for, but I found out later all I needed was to use the standard rules of rounding (I.E. .5 or above = 1 and ect.)
In the end the tip on the extra decimals frodoman gave wound up doing it, I used a combination of truncate and round in cr9 to do it.

Truncate(Round({@FieldWithExtraDecimals}, 2), 2)

Thanks a lot guys, I had to split it.
0
 
frodomanCommented:
Glad to help.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now