INT_TO_STRING

INTEGER into STRING

The function INT_TO_STRING converts a value of the data type INT into a value of the data type STRING.

Generates a result string in right-aligned decimal representation, filled with leading spaces up to the predefined maximum number of characters.

Parameters

Input

Unnamed input (INT)
Input data type

Output

Unnamed output (STRING)
Conversion result

Remarks

When using the data type STRING with small PLCs like FP-e or FP0, make sure that the length of the result string is equal to or greater than the length of the source string.

Example

Function used

String1 defined as

Result

String1:=INT_TO_STRING(-12345)

STRING[1]

'5'

STRING[2]

'45'

STRING[3]

'345'

STRING[4]

'2345'

STRING[5]

'12345'

STRING[6]

'-12345'

STRING[7]

STRING[8]

and so on...

Example

POU header

All input and output variables used for programming this function have been declared in the POU header.The same POU header is used for all programming languages.

	VAR
		INT_value: INT:=-12345;
			(*example value*)
		result_string: STRING[8]:='';
			(*result: here '-12345'*)
		@'': @'';
	END_VAR

The input variable INT_value of the data type INT is intialized by the value -12345. The output variable result_string is of the data type STRING[8]. It can store a maximum of 8 characters. Instead of using the variable INT_value, you can enter a constant directly at the function’s input contact in the body.

POU body

The INT_value of the data type INT is converted into STRING[8]. The converted value is written to result_string. When the variable INT_value = -12345, result_string shows '-12345'.

LD body

BODY
    WORKSPACE
        NETWORK_LIST_TYPE := NWTYPELD ;
        ACTIVE_NETWORK := 0 ;
    END_WORKSPACE
    NET_WORK
        NETWORK_TYPE := NWTYPELD ;
        NETWORK_LABEL :=  ;
        NETWORK_TITLE :=  ;
        NETWORK_HEIGHT := 5 ;
        NETWORK_BODY
B(B_F,INT_TO_STRING!,Instance,9,2,18,4,,?D?C);
B(B_VARIN,,INT_value,7,2,9,4,);
B(B_VAROUT,,result_string,18,2,20,4,);
L(1,0,1,5);
        END_NETWORK_BODY
    END_NET_WORK
END_BODY

ST body

result_string:= INT_TO_STRING(input_value);

IL body

Example

POU header

This example illustrates how you create a STRING[2] that appears right justified out of the data type INT.

All input and output variables used for programming this function have been declared in the POU header.The same POU header is used for all programming languages.

	VAR
		INT_value: INT:=12;
			(*example value*)
		result_string: STRING[2]:='';
			(*result: here '12'*)
		@'': @'';
		@'': @'';
	END_VAR

In this example, both an input variable INT_value of the data type INT and an output variable result_string of the data type STRING[2] are declared.

POU body

In carrying out the operation in question, the standard function RIGHT is attached to the function INT_TO_STRING. RIGHT creates a right-justified character string with the length L.

In the example, the variable INT_variable = 12 is converted by INT_TO_STRING to the dummy string '12'. The function RIGHT then creates the result_string '12'.

LD body

BODY
    WORKSPACE
        NETWORK_LIST_TYPE := NWTYPELD ;
        ACTIVE_NETWORK := 0 ;
    END_WORKSPACE
    NET_WORK
        NETWORK_TYPE := NWTYPELD ;
        NETWORK_LABEL :=  ;
        NETWORK_TITLE :=  ;
        NETWORK_HEIGHT := 9 ;
        NETWORK_BODY
B(B_F,INT_TO_STRING!,Instance,8,1,17,3,,?D?C);
B(B_VARIN,,input_string,6,1,8,3,);
B(B_F,INSERT!,Instance,4,4,9,9,,?DIN1?DIN2?DP?C);
B(B_VARIN,,'~',2,6,4,8,);
B(B_VARIN,,8,2,7,4,9,);
B(B_F,INSERT!,Instance,12,4,17,9,,?DIN1?DIN2?DP?C);
B(B_F,INSERT!,Instance,19,4,24,9,,?DIN1?DIN2?DP?C);
B(B_VAROUT,,result_string,24,5,26,7,);
B(B_VARIN,,'~',10,6,12,8,);
B(B_VARIN,,5,10,7,12,9,);
B(B_VARIN,,'~',17,6,19,8,);
B(B_VARIN,,2,17,7,19,9,);
L(1,0,1,9);
L(9,6,12,6);
L(17,6,19,6);
L(17,2,19,2);
L(3,4,3,6);
L(3,6,4,6);
L(3,3,19,3);
L(3,3,3,4);
L(19,2,19,3);
        END_NETWORK_BODY
    END_NET_WORK
END_BODY

ST body

result_string:=RIGHT(IN:=INT_TO_STRING(input_value), L:=2);

IL body

Related topics:

Modified on: 2019-01-24Feedback on this pagePanasonic hotline