Hello,
I wonder if anyone could tell me what the following program does when compiled and run on an IBM Mainframe:
IDENTIFICATION DIVISION.
PROGRAMID. A.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
INPUTOUTPUT SECTION.
DATA DIVISION.
FILE SECTION.
WORKINGSTORAGE SECTION.
01 WSVAR.
10 R PIC 9(8)v9(2).
10 A PIC S9(11) COMP3.
10 B PIC S9(9) COMP3.
PROCEDURE DIVISION.
MOVE 3 TO A.
MOVE 7 TO B.
COMPUTE R ROUNDED = ((A / B) * 100.0000).
DISPLAY R.
GOBACK.
I'm trying to understand if the use of ROUNDED forces the intermediate result of the division to 5 decimal places or not. If it does, I'd expect the result 42.86, or 42.85 if it does not.
I'm afraid I don't have access to a mainframe to try this, so any definitive answers as to what it does would be helpful.
As background, I am running the program under MicroFocus COBOL with IBM compatible arithmetic options: C ARITHMETIC(ENTCOBOL) and it gives 42.85. I'm trying to find out if this is correct or not.
I understand from IBM's documentation that the ROUNDED clause can contribute an extra decimal place to an intermediate result division, but it's unclear to me from the documentation if it does this even when the division is already being done in more decimal places than that of the result field + 1.
Any help would be greatly appreciated
Rob
Topic

Re: Intermediate result precision and ROUNDED
20130209T16:20:50ZThis is the accepted answer. This is the accepted answer.With what you have coded, the answer is 42.85, whether you use ROUNDED or not.
COMPUTE R ROUNDED = ( ( A * 100 ) / B )
With this COMPUTE, the answer is 42.86. Without the ROUNDED the answer is 42.85.
Because you do the "* 100" last, you have nothing to "round", as the loworder two digits are guaranteed to be zero.
You always, in a COMPUTE, need to code the multiplies first and the divides last, otherwise you lose significance  unless the intention is to lose digits, in which case it will be much clearer for the next person along to code separate calculations to make the effect clear. 
Re: Intermediate result precision and ROUNDED
20130211T10:56:22ZThis is the accepted answer. This is the accepted answer. BillWoodger
 20130209T16:20:50Z
With what you have coded, the answer is 42.85, whether you use ROUNDED or not.
<pre class="jivepre">COMPUTE R ROUNDED = ( ( A * 100 ) / B )
</pre>
With this COMPUTE, the answer is 42.86. Without the ROUNDED the answer is 42.85.
Because you do the "* 100" last, you have nothing to "round", as the loworder two digits are guaranteed to be zero.
You always, in a COMPUTE, need to code the multiplies first and the divides last, otherwise you lose significance  unless the intention is to lose digits, in which case it will be much clearer for the next person along to code separate calculations to make the effect clear.