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.
ROUNDAWAYFROMZERO(x,n)
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 */
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
None.
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.