Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Rounding off error

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
futuredba

New User


Joined: 08 Jan 2006
Posts: 22
Location: Delhi

PostPosted: Sat Sep 06, 2008 6:34 am    Post subject: Rounding off error
Reply with quote

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

dick scherrer

Site Director


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

PostPosted: Sat Sep 06, 2008 7:06 am    Post subject:
Reply with quote

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".
Back to top
View user's profile Send private message
dick scherrer

Site Director


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

PostPosted: Sat Sep 06, 2008 7:14 am    Post subject:
Reply with quote

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 icon_smile.gif
Back to top
View user's profile Send private message
futuredba

New User


Joined: 08 Jan 2006
Posts: 22
Location: Delhi

PostPosted: Sat Sep 06, 2008 5:52 pm    Post subject: Reply to: Rounding off error
Reply with quote

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
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8120
Location: East Dubuque, Illinois, USA

PostPosted: Sat Sep 06, 2008 7:09 pm    Post subject:
Reply with quote

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!
Back to top
View user's profile Send private message
dick scherrer

Site Director


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

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

Hello Sumit,

Quote:
Thanks for you reply,
You're welcome.

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

d
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts DB2 Program abending without giving a... rahulgarg14 DB2 7 Mon May 29, 2017 8:10 pm
No new posts Getting error while opening a variabl... apandey1 COBOL Programming 5 Fri May 05, 2017 12:22 pm
No new posts IDC2902I Error tzeche ABENDS & Debugging 2 Tue Mar 28, 2017 11:39 am
No new posts Need help with below DB2 error ashek15 DB2 3 Sat Mar 18, 2017 5:56 am
No new posts FINDREP Syntax Error seahawk789 DFSORT/ICETOOL 4 Thu Mar 09, 2017 10:11 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us