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

Author Message
divate.dilip

New User

Joined: 11 May 2009
Posts: 15
Location: Mumbai

 Posted: Mon Aug 03, 2009 4:06 pm    Post subject: Rounding Logic. My input field is having value 120. Now I am doing the calulation using the input value. 120/7.8=15.384615, but now when I multiply the 15.38 by 7.8 then 15.38*7.8=119.964 I am not getting the same value 120. Is there any way of rounding, from which i can get the same value as 120 instead of 119.96

Robert Sample

Global Moderator

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

 Posted: Mon Aug 03, 2009 4:52 pm    Post subject: There is a link to the manuals at the top of the page. Find the COBOL Language Reference manual and look up the ROUNDED option.
Marso

REXX Moderator

Joined: 13 Mar 2006
Posts: 1275
Location: Israel

 Posted: Mon Aug 03, 2009 6:04 pm    Post subject: If you would do 15.3846*7.8 then you would get 120 (rounded). You need to increase the precision of your intermediary result, that's all. (and use ROUNDED too).
Terry Heinze

JCL Moderator

Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

 Posted: Mon Aug 03, 2009 11:52 pm    Post subject: The way COBOL handles intermediate results is not what most people expect. Read carefully about them in that section of the Language Reference Manual.
Marso

REXX Moderator

Joined: 13 Mar 2006
Posts: 1275
Location: Israel

 Posted: Tue Aug 04, 2009 7:23 pm    Post subject: Reply to: Rounding Logic. So, how do you do this anyway? Do you use one or more COMPUTE statement(s) or DIVIDE and MULTIPLY?
Terry Heinze

JCL Moderator

Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

Posted: Tue Aug 04, 2009 7:47 pm    Post subject:

I don't have access to a mainframe at present, but if I remember correctly, the following should work:
 Code: 01.     05  WS-120         PIC S999      VALUE +120  COMP-3.     05  WS-7POINT8     PIC S99V9     VALUE +7.8  COMP-3.     05  WS-1ST-RESULT  PIC S999V9(4)             COMP-3.     05  WS-2ND-RESULT  PIC S999                  COMP-3.     DIVIDE   WS-120        BY WS-7POINT8 GIVING WS-1ST-RESULT ROUNDED     MULTIPLY WS-1ST-RESULT BY WS-7POINT8 GIVING WS-2ND-RESULT ROUNDED     .
WS-2ND-RESULT should equal WS-120 at this point.
 All times are GMT + 6 Hours
 Page 1 of 1

Search our Forum:

 Topic Author Forum Replies Posted Similar Topics Logic to skip Maximum time-stamp and ... vickey_dw DB2 2 Thu Feb 01, 2018 11:15 pm Is CICS BMS logic on z/OS different ... Andi1982 CICS 2 Fri Dec 01, 2017 1:56 pm Need help in building a logic Benchwarmer All Other Mainframe Topics 4 Wed Feb 22, 2017 2:49 am Wildcard logic in COBOL dudenithy COBOL Programming 13 Thu Sep 01, 2016 7:36 pm Sort Logic to extract data scorp_rahul23 DFSORT/ICETOOL 13 Tue Mar 01, 2016 1:22 am

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