RPGIV @ Work

A unique site for RPG and System i Lovers


Hi, this site will provide all what you need in System i and RPG developments.

My Name is Chamara Withanachchi, System i Expert and RPG Developer. And in the field for last 11 years.

I hope you will find lot of valuable information from this site

Converting Number to Character and vise versa Print E-mail
User Rating: / 0
Written by Chamara Withanachchi   

Use %EDITC built in function to conver to Character

%EDITC(numeric : editcode {: *ASTFILL | *CURSYM | currency-symbol})  

This function returns a character result representing the numeric value edited according to the edit code. In general, the rules for the numeric value and edit code are identical to

those for editing numeric values in output specifications. The third parameter is optional, and if specified, must be one of:


Indicates that asterisk protection is to be used. This means that leading zeros are replaced with asterisks in the returned value. For example, %EDITC(-0012.5 : 'K' : *ASTFILL)
returns '***12.5-'.


Indicates that a floating currency symbol is to be used. The actual symbol will be the one specified on the control specification in the CURSYM keyword, or the default, '$'.
When *CURSYM is specified, the currency symbol is placed in the the result just before the first significant digit. For example, %EDITC(0012.5 : 'K' : *CURSYM) returns ' $12.5 '.


Indicates that floating currency is to be used with the provided currency symbol. It must be a 1-byte character constant (literal, named constant or expression that can be
evaluated at compile time). For example, %EDITC(0012.5 : 'K' : 'X') returns ' X12.5 '.


The result of %EDITC is always the same length, and may contain leading and trailing blanks. For example, %EDITC(NUM : 'A' : '$') might return '$1,234.56CR' for one value of NUM and '

$4.56 ' for another value.


Float expressions are not allowed in the first parameter (you can use %DEC to convert a float to an editable format). In the second parameter, the edit code is specified as a

character constant; supported edit codes are: 'A' - 'D', 'J' - 'Q', 'X' - 'Z', '1' - '9'. The constant can be a literal, named constant or an expression whose value can be determined at

compile time.


Use %DEC to conver to Decimal Format


%DEC(numeric expression{:precision:decimal places})  

%DEC converts the value of the numeric expression to decimal (packed) format with precision digits and decimal places decimal positions. The precision and decimal places must be

numeric literals, named constants that represent numeric literals, or built-in functions with a numeric value known at compile-time.


Parameters precision and decimal places may be omitted if the type of numeric expression is not float. If these parameters are omitted, the precision and decimal places are taken

from the attributes of numeric expression.


Use %INT to convert to Integer format


%INT(numeric expression)  

%INT converts the value of the numeric expression to integer. Any decimal digits are truncated. This built-in function may only be used in expressions. %INT can be used to truncate

the decimal positions from a float or decimal value allowing it to be used as an array index.


<Previous   Next>