%DECH Examples
Handling Currency Symbols and Thousands Separators
If the character data is known to contain non-numeric characters such as thousands separators (for example, '1,234,567') or leading asterisks and currency symbols (for example, '$***1,234,567.89'), some preprocessing may be necessary to remove these characters from the data.
However, if Control keyword EXPROPTS(*USEDECEDIT) is specified, the thousands separators indicated by the DECEDIT keyword are considered to be part of the numeric data.
In the following example, the %XLATE built-in function is used to replace any symbol, asterisks or thousands separators with blanks.
D data s 20a inz('$1,234,567.89')
D num s 21p 9
num = %dech(%xlate('$*,' : ' ' : data)
: 21 : 9);
In the following example, Control keyword EXPROPTS(*USEDECEDIT) is specified, so it is not necessary to replace the thousands separators with blanks. In the previous example, the first operand of %XLATE, '$*,', contains a comma (,), but in the following example, the first operand of %XLATE is simply '$*'.
H EXPROPTS(*USEDECEDIT)
D data s 20a inz('$1,234,567.89')
D num s 21p 9
num = %dech(%xlate('$*' : ' ' : data)
: 21 : 9);
In the following example, the currency symbol or thousands separator might vary at runtime, so variables are used to hold these values.
num = %dech(%xlate(cursym + '*' + thousandsSep : ' ' : data)
: 21 : 9);