IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Round up using DFSORT


IBM Mainframe Forums -> DFSORT/ICETOOL
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
kellaurin

New User


Joined: 14 Apr 2009
Posts: 11
Location: Sacramento, CA

PostPosted: Tue Apr 14, 2009 11:35 pm
Reply with quote

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
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Tue Apr 14, 2009 11:50 pm
Reply with quote

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
View user's profile Send private message
kellaurin

New User


Joined: 14 Apr 2009
Posts: 11
Location: Sacramento, CA

PostPosted: Wed Apr 15, 2009 12:24 am
Reply with quote

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
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Wed Apr 15, 2009 12:42 am
Reply with quote

Yes, that's correct.
Back to top
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

PostPosted: Wed Apr 15, 2009 1:35 am
Reply with quote

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
View user's profile Send private message
kellaurin

New User


Joined: 14 Apr 2009
Posts: 11
Location: Sacramento, CA

PostPosted: Wed Apr 15, 2009 7:31 pm
Reply with quote

Good point on the truncating, not rounding down. Thanks Terry.
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Wed Apr 15, 2009 8:58 pm
Reply with quote

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
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

PostPosted: Wed Apr 15, 2009 10:12 pm
Reply with quote

I guess so. I was just trying to better distinguish between the terms "rounding down" and "truncating".
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DFSORT/ICETOOL

 


Similar Topics
Topic Forum Replies
No new posts Modifying Date Format Using DFSORT DFSORT/ICETOOL 9
No new posts Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
No new posts Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
No new posts DFsort help with SUM() DFSORT/ICETOOL 12
No new posts DFSORT - VB file RDW getting overridden DFSORT/ICETOOL 3
Search our Forums:

Back to Top