ROUNDAWAYFROMZERO Function

Purpose

Returns a value having the mode, base, and scale of x, but rounded at a digit specified by n, applying the rule of round half-away from zero.

Syntax

ROUNDAWAYFROMZERO(x,n)

Parameters

x
A FIXED DECIMAL or DFP FLOAT expression to be rounded. If x is a negative value, the absolute value is rounded and the sign is restored.
n
If x is FIXED DECIMAL, n is the digit at which rounding occurs. If x is FLOAT DFP, n is the digit representing the nth decimal place at which rounding occurs. In both cases the digit can be optionally be signed.

Description

The ROUNDAWAYFROMZERO function rounds a given value x at a specified digit x and applies the round half-away from zero rule.

If the value of x is FIXED DECIMAL or PICTURE FIXED DECIMAL, ROUNDAWAYFROMZERO returns the same results as does the ROUND function.

If the value of x is FLOAT DECIMAL and the -dfp compiler option is in effect, ROUNDAWAYFROMZERO rounds x at the nth decimal place instead of at the nth digit.

Examples

Using FIXED DECIMAL
These successive roundings of 3141.592653589793d0 produce the following values:
dcl x float dec(16) init( 3141.592653589793d0 );
display( fixed(roundawayfromzero(x,1),15,7) ); /* 3141.6000000 */
display( fixed(roundawayfromzero(x,2),15,7) ); /* 3141.5900000 */
display( fixed(roundawayfromzero(x,3),15,7) ); /* 3141.5930000 */
display( fixed(roundawayfromzero(x,4),15,7) ); /* 3141.5927000 */
display( fixed(roundawayfromzero(x,5),15,7) ); /* 3141.5926500 */
display( fixed(roundawayfromzero(x,6),15,7) ); /* 3141.5926540 */
display( fixed(roundawayfromzero(x,7),15,7) ); /* 3141.5926536 */
Using FLOAT DFP
    dcl x float dec(16) init( 6022.140857 );

    put skip list( roundawayfromzero(x,1) );
    put skip list( roundawayfromzero(x,2) );
    put skip list( roundawayfromzero(x,3) );
    put skip list( roundawayfromzero(x,4) );
    put skip list( roundawayfromzero(x,5) );
    put skip list( roundawayfromzero(x,6) );

Prints the following:

6.022100000000000E+0003
6.022140000000000E+0003
6.022141000000000E+0003
6.022140900000000E+0003
6.022140860000000E+0003
6.022140857000000E+0003

Restrictions

None.