I wonder if anyone could tell me what the following program does when compiled and run on an IBM Mainframe:
10 R PIC 9(8)v9(2).
10 A PIC S9(11) COMP-3.
10 B PIC S9(9) COMP-3.
MOVE 3 TO A.
MOVE 7 TO B.
COMPUTE R ROUNDED = ((A / B) * 100.0000).
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
Pinned topic Intermediate result precision and ROUNDED
Answered question This question has been answered.
Unanswered question This question has not been answered yet.
Updated on 2013-02-11T10:56:22Z at 2013-02-11T10:56:22Z by Rob_Nugent
BillWoodger 270005Q076263 Posts
Re: Intermediate result precision and ROUNDED2013-02-09T16: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 low-order 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.