Page 1 of 1

Rounding issue after computation

PostPosted: Thu Nov 27, 2014 6:53 pm
by sumeendar
i have a Zoned decimal field (start pos 31, length 9) in file, where i need to divide this field by 1000 and rounded.

using the below Syncsort syntax i could achieve it, but there is an issue with rounding.

31,9,ZD,DIV,+1000,ZD,LENGTH=9

for eg, For value 00000487C (000004873), after the above arithmetic operation, i am getting it rounded as 4.
Since 000004873/1000 gives 4.87 (more than 4.50), I need to round it to 5.

let me know what else need I need to do to achive this

Thanks

Re: Rounding issue after computation

PostPosted: Thu Nov 27, 2014 7:08 pm
by enrico-sorichetti
how would You do it by pencil and paper ???

Re: Rounding issue after computation

PostPosted: Thu Nov 27, 2014 7:35 pm
by BillyBoyo
Since SORT does not do rounding, why do you think you are getting it "rounded as 4"?

If you need rounding, you have to code it yourself. Something like this (untested):

  INREC IFTHEN=(WHEN=(37,1,CH,GE,C'5'),
                   OVERLAY=(31:3Z,31,6,ZD,ADD,+1,LENGTH=6)),
        IFTHEN=(WHEN=NONE,
                   OVERLAY=(31:3Z,31,6))


The 3Z will put three zoned-decimal zeros in the first three positions of your field. The first IFTHEN will add one to the first six digits of your source number and store the result after the three zeros. The second, like an ELSE, will just store the first six digits after the three zeros.

Re: Rounding issue after computation

PostPosted: Thu Nov 27, 2014 9:01 pm
by steve-myers
Assuminng 00000487C is hexadecimal, it is not "zoned decimal." It is packed decimal.

Re: Rounding issue after computation

PostPosted: Thu Nov 27, 2014 9:53 pm
by sumeendar
00000487C is zoned decimal value itself. The input field is zoned decimal format

Re: Rounding issue after computation

PostPosted: Fri Nov 28, 2014 6:07 am
by steve-myers
OK. After I put up my post, I realized there was a good chance I goofed. I let my fingers get into trouble before thinking.

I'm pretty sure 000004873/1000 = 4. The remainder is dropped and lost. However, I don't use Syncsort, and it's not in the environment I use, so I can't be sure about that.