Multiply Rounded Example


Scenario - Multiply two decimal values and rounding the result to its nearest value.

Code -

----+----1----+----2----+----3----+----4----+----5----+
       IDENTIFICATION DIVISION.
       PROGRAM-ID. MULTROUN.
       AUTHOR. MTH. 

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 WS-VAR.
          05 WS-V1    PIC 9(02)V9(2) VALUE 20.14.
          05 WS-V3    PIC 9(02)V9(2) VALUE 40.67.
          05 WS-V4    PIC 9(03).

       PROCEDURE DIVISION.

      *    Multiply WITH GIVING ROUNDED
           MULTIPLY WS-V1   BY WS-V3
             GIVING WS-V4   ROUNDED
           END-MULTIPLY.
 
           DISPLAY "Rounded Result: " WS-V4.

           STOP RUN.

Output -

Rounded Result: 819

Explaining Example -

In the above example:

  • It defines three variables in the working-storage section: WS-V1 with a value of 20.14, WS-V3 with a value of 40.67, and WS-V4.
  • It performs a multiplication operation on WS-V1 and WS-V3 using the MULTIPLY statement, and the rounded result is stored in WS-V4.
  • Finally, it displays the rounded result stored in WS-V4.