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.
- 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.
- ROUNDAWAYFROMZERO(x,0) rounds away from zero.
- CEIL(x) rounds toward positive infinity.
- FLOOR(x) rounds toward negative infinity.
- TRUNC(x) rounds toward zero.