Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist 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: 8165
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 IEW2456E error when link-editing a C ... Senthilraj JCL & VSAM 0 Fri Oct 13, 2017 3:12 pm
No new posts FTP Skip or ignore error and process ... AJAYREDDY All Other Mainframe Topics 3 Wed Sep 27, 2017 8:12 pm
No new posts Assembler Macro Copybook converted to... Ziquilix PL/I & Assembler 4 Tue Sep 26, 2017 3:07 am
No new posts FUSE - IBM MQ - CICS integration error Kevin Vaz CICS 1 Mon Sep 18, 2017 4:31 pm
No new posts Reply MQ open error Vignesh Sid COBOL Programming 6 Thu Sep 07, 2017 6:02 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us