View previous topic :: View next topic
|
Author |
Message |
divate.dilip
New User
Joined: 11 May 2009 Posts: 15 Location: Mumbai
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8697 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
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 |
|
|
Terry Heinze
JCL Moderator
Joined: 14 Jul 2008 Posts: 1249 Location: Richfield, MN, USA
|
|
|
|
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 |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
So, how do you do this anyway?
Do you use one or more COMPUTE statement(s) or DIVIDE and MULTIPLY? |
|
Back to top |
|
|
Terry Heinze
JCL Moderator
Joined: 14 Jul 2008 Posts: 1249 Location: Richfield, MN, USA
|
|
|
|
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 |
|
|
|