ROUNDAWAYFROMZERO

ROUNDAWAYFROMZERO returns the value of x rounded at a digit specified by n, following the rule of round half away from zero. The result has the mode, base, and scale of x.

Read syntax diagramSkip visual syntax diagram
>>-ROUNDAWAYFROMZERO(x,n)--------------------------------------><

Note: The ROUNDAWAYFROMZERO built-in function used to be named as ROUNDDEC.
x
A real expression that is FIXED DECIMAL or DFP FLOAT. If x is negative, the absolute value is rounded and the sign is restored.
n
An optionally-signed integer that specifies the digit at which rounding is to occur.

If x is FIXED DECIMAL or PICTURE FIXED DECIMAL, ROUNDAWAYFROMZERO produces the same results as ROUND.

If x is FLOAT DECIMAL or PICTURE FLOAT DECIMAL and the FLOAT(DFP) compiler option is in effect, ROUNDAWAYFROMZERO rounds x at the nth decimal place rather than at the nth digit (as would the ROUND built-in function in accordance with the ANSI definition). For example, these successive roundings of 3141.592653589793d0 would 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 */
ROUNDAWAYFROMZERO complements the CEIL, FLOOR, and TRUNC built-in functions.





Published: 23 December 2018