x is a fixed-point arithmetic or 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.
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 */
Description
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, may be an element expression or array name representing the value (or values, in the case of an array). If the value to be rounded is negative, its absolute value is rounded, but its sign remains unchanged.
The second argument, k, may be unsigned or signed. 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.