ADD Rounded
ADD Rounded Example
Scenario - Adding two decimal values and round the result to the nearest integer.
Code -
----+----1----+----2----+----3----+----4----+----5----+
IDENTIFICATION DIVISION.
PROGRAM-ID. ADDROUND.
AUTHOR. MTH.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-VAR.
05 WS-A PIC 9(03)V9(02) VALUE 20.72.
05 WS-B PIC 9(03)V9(02) VALUE 60.85.
05 WS-C PIC 9(03).
PROCEDURE DIVISION.
ADD WS-A TO WS-B GIVING WS-C ROUNDED.
DISPLAY "WS-C: " WS-C.
STOP RUN.
Output -
WS-C: 082
Explaining Example -
In the above example:
- It calculates the sum of two decimal numbers, WS-A and WS-B, and stores the rounded result in WS-C.
- After the addition operation, the result is 82 (which is round value of 81.57), displays the result and then terminates the program.