DOUBLE INTEGER into STRING
The function DINT_TO_STRING converts a value of the data type DINT 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.
Input
Input data type
Output
Conversion result
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.
Function used |
String1 defined as |
Result |
---|---|---|
String1:= DINT_TO_STRING(-12345678) |
STRING[2] |
'78' |
STRING[4] |
'5678' |
|
STRING[6] |
'345678' |
|
STRING[8] |
'12345678' |
|
STRING[10] |
||
STRING[12] |
'
|
|
and so on... |
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
input_value: DINT:=12345678;
result_string: STRING[11]:='';
END_VAR
The input variable input_value of the data type DINT is intialized by the value 12345678. The output variable result_string is of the data type STRING[11]. It can store a maximum of 11 characters. Instead of using the variable input_value, you can enter a constant directly at the function’s input contact in the body.
The input_value of the data type DINT is converted into STRING[11]. The converted value is written to result_string. When the variable input_value = 12345678, result_string shows '12345678'.
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,DINT_TO_STRING!,Instance,8,1,17,3,,?D?C);
B(B_VARIN,,input_string,6,1,8,3,);
B(B_VAROUT,,result_string ,17,1,19,3,);
L(1,0,1,5);
END_NETWORK_BODY
END_NET_WORK
END_BODY
result_string:=DINT_TO_STRING(input_value);