Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref

Author Message
futuredba

New User

Joined: 08 Jan 2006
Posts: 22
Location: Delhi

 Posted: Sat Sep 06, 2008 6:34 am    Post subject: Rounding off error Hi, Look at this code: WS-VAR1 pic 9(2)V9(9) value 1.939491221. WS-VAR2 pic 9(2)V9(3) value 0. Multiply 1 by WS-VAR1 giving WS-VAR2 ROUNDED. After executing the above code, i was expecting 1.940 in WS-VAR2 but strangely it had 1.939. It seems to me that since WS-VAR2 has only 3 decimal places so it was rounding off the resultant value from 4th decimal places. What should I do so that it does the rounding off from the last decimal place of the resultant value not just 1 decimal place more than the receiver field? Thanks, Sumit

dick scherrer

Site Director

Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

Posted: Sat Sep 06, 2008 7:06 am    Post subject:

Hello,

 Quote: i was expecting 1.940 in WS-VAR2 but strangely it had 1.939
I believe you need to change your expectation. In your example, ROUND is working exactly as it should, not strangely.
 Quote: When the size of the fractional result exceeds the number of places provided for its storage, truncation occurs unless ROUNDED is specified. When ROUNDED is specified, the least significant digit of the resultant identifier is increased by 1 whenever the most significant digit of the excess is greater than or equal to 5.
The most significant digit of the excess is 4, the result is not "rounded up".
dick scherrer

Site Director

Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

Posted: Sat Sep 06, 2008 7:14 am    Post subject:

Hello again,

 Code: WS-VAR1 pic 9(2)V9(9) value 1.939491221. WS-VAR2 pic 9(2)V9(3) value 0.

You might try:
 Code: COMPUTE WS-VAR2 = WS-VAR1 + .000999999
I'm not able to test just now due to some system maintenance, but i believe that will give the result you want.

If not, post back here and i'll figure out where i went wrong
futuredba

New User

Joined: 08 Jan 2006
Posts: 22
Location: Delhi

 Posted: Sat Sep 06, 2008 5:52 pm    Post subject: Reply to: Rounding off error Hi, According to the defination of rounding off in math, that i was taught during my school days, 1.93949 should be first rounded up to 1.9395 and it should be again rounded up to 1.940. So i thought cobol keyword ROUNDED is not doing what rounding means in mathematics. But I just searched some web sites over internet and found that rounding off in mathematics means exactly what ROUNDED doing in cobol. I didn't want to make the number 1.940 intentionally. I just wanted to make sure that it is rounded off correctly as far as mathematics is corcerned. Thanks for you reply, Sumit
Robert Sample

Global Moderator

Joined: 06 Jun 2008
Posts: 8280
Location: Dubuque, Iowa, USA

 Posted: Sat Sep 06, 2008 7:09 pm    Post subject: Sumit, I've never heard of rounding one digit at a time as you were taught in school -- I've always heard rounding only applies to the digit after the last significant digit and 0 to 4 round down, 5 to 9 round up. I guess even after getting a bachelor's degree in mathematics, there's still stuff to learn!
dick scherrer

Site Director

Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

Posted: Sun Sep 07, 2008 12:00 am    Post subject: Reply to: Rounding off error

Hello Sumit,

You're welcome.

Thank you for the reply telling us that all is well now

d
 All times are GMT + 6 Hours
 Page 1 of 1

Search our Forum:

 Topic Author Forum Replies Posted Similar Topics 3270 Data stream error Benchwarmer CICS 4 Tue Apr 17, 2018 12:06 am VSAM file NOT Found error while proce... SumaReva CICS 5 Wed Apr 11, 2018 9:54 pm IMS error U4038 while executing my PL... abdulrafi IMS DB/DC 2 Thu Feb 08, 2018 1:05 pm -502 Error - Cursor already open anand jeyapaul DB2 7 Sun Oct 29, 2017 4:22 am IEW2456E error when link-editing a C ... Senthilraj JCL & VSAM 0 Fri Oct 13, 2017 3:12 pm

 © 2003-2017 IBM MAINFRAME Software Support Division
 Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us