ROUND
ROUND returns the value of x rounded at a digit specified by n. The result has the mode, base, and scale of x.
- x
- Real expression. If x is negative, the absolute value is rounded and the sign is restored.
- n
- Optionally-signed integer. It specifies the digit at which rounding is to occur.
ROUND of FIXED
(max(1,min(p-q+1+n,N)),n)
Where
(p,q) is the precision of x, and N is the
maximum number of digits allowed. Hence, n specifies the scaling factor of
the result.n must conform to the limits of scaling-factors for FIXED data. If n is greater than 0, rounding occurs at the (n)th digit to the right of the point. If n is zero or negative, rounding occurs at the (1-n)th digit to the left of the point.
In ROUND(x,n), n must not specify a digit too far to the right or too far to the left. To express this in mathematical terms: n <= q and 0 <= (p - q) + n must be true.
round(x,n) = sign(x)*(b-n)* floor(abs(x)* (bn) + 1/2)
dcl X fixed dec(5,4) init(6.6666);
put skip list( round(X,2) );
ROUND of IEEE decimal floating point
The precision of an IEEE DECIMAL FLOAT result is the same as that of the source argument.
round(x,n) = sign(x)*(b(e-n))* floor(abs(x)* (b(n-e)) + 1/2)
dcl x float dec(16) init( 3.1415926d0 );
display( round(x,1) ); /* 3.000000000000000E+0000 */
display( round(x,2) ); /* 3.100000000000000E+0000 */
display( round(x,3) ); /* 3.140000000000000E+0000 */
display( round(x,4) ); /* 3.142000000000000E+0000 */
display( round(x,5) ); /* 3.141600000000000E+0000 */
display( round(x,6) ); /* 3.141590000000000E+0000 */
ROUND of IEEE binary floating point
The precision of an IEEE binary floating point result is the same as that of the source argument.
Under the compiler option USAGE(ROUND(IBM)), the value of the result is the same as the source except on z/OS where if the source is not zero, then the result is obtained by turning on the rightmost bit in the source.
round(x,n) = sign(x)*(b(e-n))* floor(abs(x)* (b(n-e)) + 1/2)
dcl x float bin(53) init( 3.1415926d0 );
display( round(x,1) ); /* 4.000000000000000E+0000 */
display( round(x,2) ); /* 3.000000000000000E+0000 */
display( round(x,3) ); /* 3.000000000000000E+0000 */
display( round(x,4) ); /* 3.250000000000000E+0000 */
display( round(x,5) ); /* 3.125000000000000E+0000 */
display( round(x,6) ); /* 3.125000000000000E+0000 */
display( round(x,7) ); /* 3.156250000000000E+0000 */
ROUND of IBM hexadecimal floating point
The precision of an IBM hexadecimal floating point result is the same as that of the source argument.
Under the compiler option USAGE(ROUND(IBM)), the value of the result is the same as the source except on z/OS where if the source is not zero, then the result is obtained by turning on the rightmost bit in the source.
round(x,n) = sign(x)*(b(e-n))* floor(abs(x)* (b(n-e)) + 1/2)
dcl x float bin(53) init( 3.1415926d0 );
display( round(x,1) ); /* 3.000000000000000E+00 */
display( round(x,2) ); /* 3.125000000000000E+00 */
display( round(x,3) ); /* 3.140625000000000E+00 */
display( round(x,4) ); /* 3.141601562500000E+00 */
display( round(x,5) ); /* 3.141586303710938E+00 */
display( round(x,6) ); /* 3.141592979431152E+00 */