ROUNDDEC returns the value of x rounded at a digit specified by n. The result has the mode, base, and scale of x.
|
If x is FIXED DECIMAL or PICTURE FIXED DECIMAL, ROUNDDEC produces the same results as ROUND.
If x is FLOAT DECIMAL or PICTURE FLOAT DECIMAL and the FLOAT(DFP) compiler option is in effect, ROUNDDEC 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(rounddec(x,1),15,7) ); /* 3141.6000000 */
display( fixed(rounddec(x,2),15,7) ); /* 3141.5900000 */
display( fixed(rounddec(x,3),15,7) ); /* 3141.5930000 */
display( fixed(rounddec(x,4),15,7) ); /* 3141.5927000 */
display( fixed(rounddec(x,5),15,7) ); /* 3141.5926500 */
display( fixed(rounddec(x,6),15,7) ); /* 3141.5926540 */
display( fixed(rounddec(x,7),15,7) ); /* 3141.5926536 */
ROUNDDEC complements the CEIL, FLOOR, and TRUNC built-in functions.