Unsigned DOUBLE INTEGER into STRING
The function UDINT_TO_STRING converts a value of the data type UDINT 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
Output
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:= UDINT_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_string: UDINT:=12345678;
(*example value*)
result_string: STRING[11]:='';
(*result: here '12345678'*)
END_VAR
The input variable input_value of the data type UDINT 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,UDINT_TO_STRING!,,14,1,24,3,,?D?C);
B(B_VARIN,,input_string,12,1,14,3,);
B(B_VAROUT,,result_string,24,1,26,3,);
L(1,0,1,5);
END_NETWORK_BODY
END_NET_WORK
END_BODY
result_string:=UDINT_TO_STRING(input_value);