title: compute rounded in cobol
body: <p>I am confused with the rounded in the compute function in cobol.</p>
  
  <p>Declaration:</p>
  
  <pre><code>VAR-A      PIC  S9(9)V99 COMP-3.
  VAR-B      PIC  S9(9)V9(6) COMP-3.
  </code></pre>
  
  <p>Procedure.</p>
  
  <pre><code>MOVE +12.08 TO VAR-A.
  MOVE +6.181657 TO VAR-B.
  
  
  COMPUTE VAR-A ROUNDED = VAR-A + VAR-B.
  </code></pre>
  
  <p>Will the result of VAR-A be 18.27 or 18.26? What would cobol do upon computing?
  Would it round VAR-B first to the decimal places specified in VAR-A or will cobol add the 2 variables then round them up to the decimal places specified in VAR-A?</p>
  
  <p>Any help will be appreciated.</p>
  
  <p>@NealB,</p>
  
  <p>How about this example:</p>
  
  <p>DECLARATION:</p>
  
  <pre><code>01  VAR-ARRAY  OCCURS 22 TIMES.
      03  VAR-A      PIC  S9(9)V9(6) COMP-3.
  
  
  01  VAR-B      PIC  S9(9)V99 COMP-3.
  </code></pre>
  
  <p>Supposing VAR-A is an array, and the following are its values:</p>
  
  <pre><code>VAR-A(01) =  123.164612
  VAR-A(02) =  12.07865
  VAR-A(03) =  6.181657
  VAR-A(04) =  1.744353
  VAR-A(05) =  6.118182
  VAR-A(06) =  1.744353
  VAR-A(07) =  6.158715
  VAR-A(08) =  1.744353
  VAR-A(09) =  6.194759
  VAR-A(10) =  1.744353
  VAR-A(11) =  3.037896
  VAR-A(12) =  1.743852
  VAR-A(13) =  6.14653
  VAR-A(14) =  1.744353
  VAR-A(15) =  0.000377
  VAR-A(16) =  1.743852
  VAR-A(17) =  6.144363
  VAR-A(18) =  1.743852
  VAR-A(19) =  0.007649
  VAR-A(20) =  1.744353
  VAR-A(21) =  0.000377
  VAR-A(22) =  1.744353
  </code></pre>
  
  <p>VAR-B's value is:</p>
  
  <pre><code>VAR-B = 405.25
  </code></pre>
  
  <p>PROCEDURE:</p>
  
  <pre><code>PERFORM VAR-IDX FROM 1 BY 1 UNTIL VAR-IDX &gt; 22
    COMPUTE VAR-B ROUNDED = VAR-B + VAR-A(VAR-IDX)
  END-PERFORM.
  </code></pre>
  
  <p>Why do I get 597.87 for VAR-B as a result after the computation?</p>