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

Author Message
hsk

New User

Joined: 28 Nov 2006
Posts: 69
Location: India

Posted: Mon Feb 26, 2007 1:34 pm    Post subject: Why COMPUTE ROUNDED not giving exact value

 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 ?

sachin_star3
Warnings : 1

New User

Joined: 30 Sep 2006
Posts: 78
Location: pune

 Posted: Mon Feb 26, 2007 3:40 pm    Post subject: 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
William Thompson

Global Moderator

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

 Posted: Mon Feb 26, 2007 3:46 pm    Post subject: Intermediate results? What would COMPUTE WS-VAR-1 ROUNDED = (365.0 / 12.0) * 11.0 result in?
dick scherrer

Site Director

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

 Posted: Mon Feb 26, 2007 10:46 pm    Post subject: 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. . . .
ibm4me

New User

Joined: 23 Oct 2006
Posts: 3

 Posted: Tue Feb 27, 2007 8:23 am    Post subject: Re: Why COMPUTE ROUNDED not giving exact value 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
hsk

New User

Joined: 28 Nov 2006
Posts: 69
Location: India

 Posted: Tue Feb 27, 2007 11:41 am    Post subject: 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
dick scherrer

Site Director

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

Posted: Wed Feb 28, 2007 5:01 am    Post subject:

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.
William Thompson

Global Moderator

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

 Posted: Wed Feb 28, 2007 5:10 am    Post subject: Well, I was close....
hsk

New User

Joined: 28 Nov 2006
Posts: 69
Location: India

 Posted: Wed Feb 28, 2007 9:46 am    Post subject: oohh, thanks dick ......... that works ..........
dick scherrer

Site Director

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

 Posted: Wed Feb 28, 2007 8:21 pm    Post subject: You're welcome
 All times are GMT + 6 Hours
 Page 1 of 1

Search our Forum:

 Topic Author Forum Replies Posted Similar Topics Compute statement with Cobol Z/os 5.2 Chetan Kumar COBOL Programming 2 Fri May 11, 2018 8:02 pm WRITE to VSAM giving duplicate RC picus_mf CICS 1 Fri Feb 23, 2018 2:52 pm DB2 Program abending without giving a... rahulgarg14 DB2 7 Mon May 29, 2017 8:10 pm Join giving more records than expected Danielle.Filteau SYNCSORT 2 Thu Mar 09, 2017 3:28 am ROUNDED Problem with COMPUTE statement shalem COBOL Programming 11 Thu Feb 09, 2017 8:16 pm

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