ROUND Function

Purpose

Rounds a given value at a specified digit and pads spare digit positions with zeros.

Syntax

ROUND(x,k)

Parameters

x is a fixed-point arithmetic or fixed decimal picture value to be rounded, and k is an integer constant that specifies the digit at which the value x is to be rounded.

Descriptions

ROUND of Fixed Decimal
The ROUND function rounds a given value x at a specified digit and pads positions k+1 to q (q is the scale factor) with zeros. The result is the value of x rounded such that the kth position of x is expressed to its nearest integer. For example, if the argument is 8.77 and it is desired to round to the first fractional digit, the result would be 8.80.

The first argument, x, is an expression. If the value to be rounded is negative, its absolute value is rounded, but its sign remains unchanged.

The second argument, k, may be an unsigned or signed digit. If k is positive, rounding occurs at the kth digit to the right of the decimal (or binary) point in the first argument; if k is zero, rounding occurs at the first digit to the left of the decimal (or binary) point in the first argument; if k is negative, rounding occurs at the (1 - k) digit to the left of the decimal (or binary) point in the first argument.

Examples

DCL (X,K) DECIMAL FIXED (7,4); 
X = 123.7261;
K = ROUND(X,3);       /* K IS NOW 123.7260 */ 
K = ROUND(X,2);       /* K IS NOW 123.7300 */
K = ROUND(X,1);       /* K IS NOW 123.7000 */
K = ROUND(X,0);       /* K IS NOW 124.0000 */
X = -123.7261;
K = ROUND(X,2);       /* K IS NOW -123.7300 */
K = ROUND(X,0);       /* K IS NOW -124.0000 */
K = ROUND(X,-1);      /* KIS NOW -120.0000 */
X = 9.9999;
K = ROUND(X,0);       /* K IS NOW 10.0000 */
dcl x float dec(16) init( 6.283185307179586E+0003 );

put skip list( round(x,5) );  /* 6.283200000000000E+0003 */
put skip list( round(x,6) );  /* 6.283190000000000E+0003 */
put skip list( round(x,7) );  /* 6.283185000000000E+0003 */
put skip list( round(x,8) );  /* 6.283185300000000E+0003 */
put skip list( round(x,9) );  /* 6.283185310000000E+0003 */
put skip list( round(x,10) ); /* 6.283185307000000E+0003 */
put skip list( round(x,11) ); /* 6.283185307200000E+0003 */
Round of IEEE Float Decimal (DFP)
The precision of an IEEE floating point decimal (DFP) result is same precision as that of the source argument.

Rounding of FLOAT DECIMAL occurs at the nth decimal place, as opposed to the nth digit when ROUND of FIXED DECIMAL.

Example

    dcl x float dec(16) init( 6022.140857 );

    put skip list( round(x,5) );
    put skip list( round(x,6) );
    put skip list( round(x,7) );
    put skip list( round(x,8) );
    put skip list( round(x,9) );
    put skip list( round(x,10) );

Prints the following:

6.022100000000000E+0003
6.022140000000000E+0003
6.022141000000000E+0003
6.022140900000000E+0003
6.022140860000000E+0003
6.022140857000000E+0003
Round of IEEE Float Binary
ROUND of an IEEE floating point binary result is same as the source argument.

Restrictions

None