Page 1 of 1

How to get decimal places?

PostPosted: Thu Nov 15, 2012 5:08 pm
by ranga_subham
Hi,

I ran below SORT but getting rounded value (known thing) and expecting to get 500.75".

//STEP0001 EXEC PGM=SORT                             
//SORTIN   DD *                                     
2004                                                 
//SORTOUT  DD SYSOUT=*                               
//SYSOUT   DD SYSOUT=*                               
//SYSIN    DD *                                     
  SORT FIELDS=COPY                                   
  INREC IFTHEN=(WHEN=INIT,OVERLAY=(10:1,4,ZD,DIV,+4))


Output:
********************************* TOP OF DATA **********************************
2004                 501                                                       
******************************** BOTTOM OF DATA ********************************


Expected Output:
********************************* TOP OF DATA **********************************
2004                 500.75                                                       
******************************** BOTTOM OF DATA ********************************


Please help.

Thanks.

Re: How to get decimal places?

PostPosted: Thu Nov 15, 2012 5:19 pm
by BillyBoyo
2004 divided by 4 is 501.

501 multiplied by 4 is 2004.

So your example is poor. We'll assume 2003.

Sort does not do "rounding". If you want rounding, you have to code it yourself.

Sort does not know about implied decimal places. If you want a result of 50075 then you have to make the value to be divided 200300. You then use an EDIT to give you the decimal places you want.

Re: How to get decimal places?

PostPosted: Thu Nov 15, 2012 5:25 pm
by enrico-sorichetti
:shock:

Your arithmetic teacher should be tarred, feathered, hanged and left on the gallows until it rots :mrgreen:

Re: How to get decimal places?

PostPosted: Thu Nov 15, 2012 5:55 pm
by ranga_subham
Yes Bill.....it was 2003 :oops: .....what if I have more different values instead of one input record?

Thanks.

Re: How to get decimal places?

PostPosted: Thu Nov 15, 2012 6:09 pm
by ranga_subham
Bill, am I right with this code? Got results though :)

//*====================================================================*
//STEP0001 EXEC PGM=SORT                                               
//SORTIN   DD *                                                         
2003                                                                   
2005                                                                   
//SORTOUT  DD SYSOUT=*                                                 
//SYSOUT   DD SYSOUT=*                                                 
//SYSIN    DD *                                                         
 SORT FIELDS=COPY                                                       
 INREC IFTHEN=(WHEN=INIT,                                               
               OVERLAY=(10:1,4,ZD,MUL,+100,DIV,+4,EDIT=(TTT.TT)))       
//*                                                                     


Thanks.

Re: How to get decimal places?

PostPosted: Thu Nov 15, 2012 7:07 pm
by BillyBoyo
Yes, that is one way to do it. Do you know how it works, given that you are starting with only four bytes?

  OVERLAY=(15:C'00',10:1,6,ZD,DIV,+4,EDIT=(TTT.TT)))


Would be another.

Re: How to get decimal places?

PostPosted: Thu Nov 15, 2012 9:29 pm
by ranga_subham
Thanks Bill.......nice idea ;)

Re: How to get decimal places?

PostPosted: Thu Nov 15, 2012 9:38 pm
by ranga_subham
Bill, all attempts with your suggested code end with S0C7 :o

Re: How to get decimal places?

PostPosted: Thu Nov 15, 2012 9:44 pm
by BillyBoyo
Sorry, 15 should have been 5 :-) It is adding the two zeros to your input.

Better, perhaps, so is not there permanently

  OVERLAY=(10:1,4,C'00',10:10,6,ZD,DIV,+4,EDIT=(TTT.TT)))

Re: How to get decimal places?

PostPosted: Thu Nov 15, 2012 9:49 pm
by ranga_subham
ran it with latest code and got the results :D