%DECH Built-In Functions in rpgle
It is used to Round-off decimal places.
%DECH is the same as %DEC built-in function except that the half adjust is also performed if the expression is a decimal or float value.
Half-adjust is a rounding process in which less significant digits are dropped off to get the rounded result. If the less significant one-half or more of the number base then one is added to the next more significant digit. See example below understand this process.
Columns . . . : 6 80 AMIT/QRPGSRC
SEU==> TESTRPG
FMT * *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8
*************** Beginning of data *****************************************
0001.00 DChar001 S 15A
0002.00 DDec001 S 10S 2
0003.00 C
0004.00 C Eval Char001 = '-2017.4812'
0005.00 C
0006.00 C* Convert CHAR to decimal(7,2)
0007.00 C Eval Dec001= %DECH(Char001:10:2)
0008.00 C
0009.00 C* Convert to CHAR and display
0010.00 C Eval Char001= %CHAR(Dec001)
0011.00 C Char001 DSPLY
0012.00 C
0013.00 C SETON LR
****************** End of data ********************************************
Output
DSPLY -2017.48
In above example, if Char001 = '-2017.4852', then we will get below result:
DSPLY -2017.49
In above example, if Char001 = '-2017.4850', then we will get below result:
DSPLY -2017.49