%DEC has three forms, and which one is legal depends on the operand's type.
total = %DEC(price * qty); // precision and scale come from the expression
isoDate = %DEC(myDate : *ISO); // 2026-07-13 becomes 20260713
amount = %DEC(text : 7 : 2); // explicit precision and scale
| Operand | Accepted forms |
|---|---|
| Packed, zoned, integer, unsigned (or an expression of them) | %DEC(value) - the precision and scale are taken from the operand's own attributes - or %DEC(value : precision : scale) |
| Float or character | %DEC(value : precision : scale) only. Neither carries an inherent number of digits, so the precision and scale may not be omitted |
| Date, time, timestamp | %DEC(value) or %DEC(value : format) only. The result is the value's digits read as a whole number, with the separators dropped - an *ISO date gives 20260713. A precision and scale may not be given |
Anything else is rejected with TRN2007. In particular a precision without a
scale - %DEC(value : 7) - is never valid for a numeric operand, because the
two-operand form is the date/time format form.
%DECH is %DEC with half-adjust applied to the converted value, and it
always takes all three operands: %DECH(value : precision : scale). It has
neither the one-operand form nor the date form, since rounding is only meaningful
against a target scale. %DEC truncates where %DECH rounds:
DCL-S pk PACKED(7:2) INZ(12.36);
r = %DEC(pk : 7 : 1); // 12.3 - truncated
r = %DECH(pk : 7 : 1); // 12.4 - half-adjusted