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 Logic.

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

New User


Joined: 11 May 2009
Posts: 15
Location: Mumbai

PostPosted: Mon Aug 03, 2009 4:06 pm    Post subject: Rounding Logic.
Reply with quote

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

Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7992
Location: Bellevue, IA

PostPosted: Mon Aug 03, 2009 4:52 pm    Post subject:
Reply with quote

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

REXX Moderator


Joined: 13 Mar 2006
Posts: 1226
Location: Israel

PostPosted: Mon Aug 03, 2009 6:04 pm    Post subject:
Reply with quote

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

JCL Moderator


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

PostPosted: Mon Aug 03, 2009 11:52 pm    Post subject:
Reply with quote

The way COBOL handles intermediate results is not what most people expect. Read carefully about them in that section of the Language Reference Manual.
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1226
Location: Israel

PostPosted: Tue Aug 04, 2009 7:23 pm    Post subject: Reply to: Rounding Logic.
Reply with quote

So, how do you do this anyway?

Do you use one or more COMPUTE statement(s) or DIVIDE and MULTIPLY?
Back to top
View user's profile Send private message
Terry Heinze

JCL Moderator


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

PostPosted: Tue Aug 04, 2009 7:47 pm    Post subject:
Reply with quote

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.
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 Need help in building a logic Benchwarmer All Other Mainframe Topics 4 Wed Feb 22, 2017 2:49 am
No new posts Wildcard logic in COBOL dudenithy COBOL Programming 13 Thu Sep 01, 2016 7:36 pm
No new posts Sort Logic to extract data scorp_rahul23 DFSORT/ICETOOL 13 Tue Mar 01, 2016 1:22 am
No new posts Need a logic to validate the data in ... sandeep kumar302 COBOL Programming 17 Mon Feb 01, 2016 3:30 pm
No new posts Tricky sort logic required pgopi92 DFSORT/ICETOOL 3 Mon Jan 25, 2016 3:29 pm


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