REBOL for COBOL programmers

Go to table of contents Go to feedback page

ROUNDED

Date written: March 25, 2013
Date revised:
Date reviewed:

This page explains some REBOL equivalents of ROUNDED.


COBOL ROUNDED

The various COBOL arithmentic operators have the optional ROUNDED clause. For example,

DIVIDE { identifier-1 } INTO { identifier-2 } GIVING identifier-3 [ROUNDED] REMAINDER identifier-4.
       { literal-1    }      { literal-2    }
COMPUTE identifier-1 ROUNDED = arithmetic-expression-1
and so on for all the other statements (ADD, SUBTRACT, MULTIPLY).

The REBOL equivalent

REBOL has a separate function for rounding. It appears to be not present in earlier versions.

identifier-2: round identifier-1                 
The "round" function has refinements for rounding up or down, which way to go when the number is a half, and so on. Here is the "help" clipped out of the interpreter console (obtained with "help round").
>> help round
USAGE:
    ROUND n /even /down /half-down /floor /ceiling /half-ceiling /to scale

DESCRIPTION:
     Returns the nearest integer. Halves round up (away from zero) by default.
     ROUND is a function value.

ARGUMENTS:
     n -- The value to round (Type: number money time)

REFINEMENTS:
     /even -- Halves round toward even results
     /down -- Round toward zero, ignoring discarded digits. (truncate)
     /half-down -- Halves round toward zero
     /floor -- Round in negative direction
     /ceiling -- Round in positive direction
     /half-ceiling -- Halves round in positive direction
     /to -- Return the nearest multiple of the scale parameter
         scale -- Must be a non-zero value (Type: number money time)

(SPECIAL ATTRIBUTES)
     catch