View previous topic :: View next topic
|
Author |
Message |
kellaurin
New User
Joined: 14 Apr 2009 Posts: 11 Location: Sacramento, CA
|
|
|
|
I want to calculate a percentage for a number but the result is always rounding down. Here is my statement:
24:(24,9,ZD,MUL,+8605,DIV,+10000),M18,LENGTH=9,
This is the value of my input field: 00000458B
This is the value of my output field: 39.42
I want it to be 39.43 by rounding the actual result of 39.42811.
Any help would be appreciated. |
|
Back to top |
|
|
Frank Yaeger
DFSORT Developer
Joined: 15 Feb 2005 Posts: 7129 Location: San Jose, CA
|
|
|
|
I believe DFSORT control statements like the following will do the rounding up you want:
Code: |
OPTION COPY
INREC BUILD=(24:(((24,9,ZD,MUL,+8605),ADD,+5000),DIV,+10000),
M18,LENGTH=9)
|
|
|
Back to top |
|
|
kellaurin
New User
Joined: 14 Apr 2009 Posts: 11 Location: Sacramento, CA
|
|
|
|
Thanks for the fast reply Frank, that worked perfectly. So basically DFSORT rounds down, so I have to trick it by adding .5 to every number before the final result rounds down? |
|
Back to top |
|
|
Frank Yaeger
DFSORT Developer
Joined: 15 Feb 2005 Posts: 7129 Location: San Jose, CA
|
|
|
|
Yes, that's correct. |
|
Back to top |
|
|
Terry Heinze
JCL Moderator
Joined: 14 Jul 2008 Posts: 1249 Location: Richfield, MN, USA
|
|
|
|
Rounding down might be an inaccurate description. I'd guess that "truncating" would be a better description. And Frank's technique can be used any time a result is being truncated because of the lack of a "rounding" function. Simply add 5 to the digit position that is being truncated (the digit immediately to the right of the one you want to round to). |
|
Back to top |
|
|
kellaurin
New User
Joined: 14 Apr 2009 Posts: 11 Location: Sacramento, CA
|
|
|
|
Good point on the truncating, not rounding down. Thanks Terry. |
|
Back to top |
|
|
Frank Yaeger
DFSORT Developer
Joined: 15 Feb 2005 Posts: 7129 Location: San Jose, CA
|
|
|
|
Terry,
DFSORT does integer arithmetic. The decimal places are not kept for the result of a divide. Is that what you mean by "truncating"? |
|
Back to top |
|
|
Terry Heinze
JCL Moderator
Joined: 14 Jul 2008 Posts: 1249 Location: Richfield, MN, USA
|
|
|
|
I guess so. I was just trying to better distinguish between the terms "rounding down" and "truncating". |
|
Back to top |
|
|
|