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
 

 

Why COMPUTE ROUNDED not giving exact value

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

New User


Joined: 28 Nov 2006
Posts: 69
Location: India

PostPosted: Mon Feb 26, 2007 1:34 pm    Post subject: Why COMPUTE ROUNDED not giving exact value
Reply with quote

Code:


01  WS-VAR-1              PIC 9(9).   
01  WS-VAR-2              PIC 9(9)V99.

COMPUTE WS-VAR-1 ROUNDED  = (365 / 12) * 11     => 334

COMPUTE WS-VAR-2 = (365 / 12) * 11
COMPUTE WS-VAR-1 ROUNDED = WS-VAR-2             => 335


Do i need to store result in some variable ??
Why COMPUTE WS-VAR-1 ROUNDED = (365 / 12) * 11 not giving 335 directly ?
Back to top
View user's profile Send private message

sachin_star3
Warnings : 1

New User


Joined: 30 Sep 2006
Posts: 78
Location: pune

PostPosted: Mon Feb 26, 2007 3:40 pm    Post subject:
Reply with quote

answer:

in compute with rouded always gives result approximate
but in 2nd case you have not done computation
i.e 34.58 = 35

so its better you
mention
ws-var-1 pic 9(9)v9
so you will get 34.6
correct me i am wronge
from -
sachin borase
pune
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3158
Location: Tucson AZ

PostPosted: Mon Feb 26, 2007 3:46 pm    Post subject:
Reply with quote

Intermediate results?
What would
COMPUTE WS-VAR-1 ROUNDED = (365.0 / 12.0) * 11.0
result in?
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: Mon Feb 26, 2007 10:46 pm    Post subject:
Reply with quote

Hello,

Please look up ROUNDED in your Fine Manual. Rounded results are not approximate - they are exact to whatever you specify.

In your example, none of the fields have any decimal places defined, so only whole numbers are considered. If the "answer" was 334.9976, you would get 334. Rounding occurs with digits to the right of the decimal. Significant digits are not "rounded up". Let's say you have 1045 and divide it by 55 - the answer is 19. Should that round up to 20? I don't believe so. . . .
Back to top
View user's profile Send private message
ibm4me

New User


Joined: 23 Oct 2006
Posts: 3

PostPosted: Tue Feb 27, 2007 8:23 am    Post subject: Re: Why COMPUTE ROUNDED not giving exact value
Reply with quote

picture clause

PIC 9(3)V9. ---->1
PIC 9(3). ----->2

Value
123.25 (1)
123 (2)

Truncated
123.2 (1)
123 (2)

Rounded
123.3 (1)
123 (2)


The ROUNDED option takes effect when, after decimal point alignment, the result calculated must be truncated on the right hand side.

The option adds 1 to the receiving item when the leftmost truncated digit has an absolute value of 5 or greater.




Correct me if am wrong
Back to top
View user's profile Send private message
hsk

New User


Joined: 28 Nov 2006
Posts: 69
Location: India

PostPosted: Tue Feb 27, 2007 11:41 am    Post subject:
Reply with quote

COMPUTE WS-VAR-1 ROUNDED = (365.0 / 12.0) * 11.0 is resulting in 334


if i replace the formula (365.0 / 12.0) * 11.0 by number 334.58 then the ans is 335

That is what confusion is ?
If it's rounding up 334.58 to 335,
then why it is not rounding when i use formula (365.0 / 12.0) * 11.0 and not number 334.58
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: Wed Feb 28, 2007 5:01 am    Post subject:
Reply with quote

Hello,

If you use (365.00 / 12) * 11 it will give the rounding you expect.

Previously, there was not enough precision. This from the Fine Manual:
Quote:
Note: You must define the operands of any arithmetic statements with
enough decimal places to give the desired accuracy in the final result.
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3158
Location: Tucson AZ

PostPosted: Wed Feb 28, 2007 5:10 am    Post subject:
Reply with quote

Well, I was close.... icon_redface.gif
Back to top
View user's profile Send private message
hsk

New User


Joined: 28 Nov 2006
Posts: 69
Location: India

PostPosted: Wed Feb 28, 2007 9:46 am    Post subject:
Reply with quote

oohh, thanks dick .........

that works ..........
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: Wed Feb 28, 2007 8:21 pm    Post subject:
Reply with quote

You're welcome icon_smile.gif
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 Quick3270 Macro is giving error for a... Tanuz All Other Mainframe Topics 4 Sat Dec 06, 2014 8:41 am
No new posts SUM FIELDS Giving S0C7 Indrajit_57 JCL & VSAM 4 Tue Jul 01, 2014 4:01 pm
No new posts ICETOOL - JOINKEYS - VB input giving ... John W Perry DFSORT/ICETOOL 11 Thu Apr 03, 2014 1:14 am
No new posts Compute statement not working sandeep kumar302 COBOL Programming 5 Wed Apr 02, 2014 7:12 pm
No new posts IEBGENER giving IEB351I I/O ERROR umashankar pathak JCL & VSAM 18 Mon Mar 10, 2014 11:39 pm


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