DINT_TO_DECSTR

This function converts a signed decimal number into a decimal string (base 10).
FUNCTION DINT_TO_DECSTR : T_MaxString
VAR_INPUT
in : DINT;
iPrecision : INT;
END_VAR
in: The decimal number requiring conversion.
iPrecision: Minimum number of displayed digits (digits). If the actual number of significant digits is less than the iPrecision parameter, the resulting string is filled with zeros from the left. If the number of significant digits is greater than the iPrecision parameter, the resulting string is not cut off! If the iPrecision parameter and the in parameter are zero, the resulting string is empty. For negative numbers, the negative sign will appear in the resulting string.
Example in ST:
PROGRAM MAIN
VAR
s1 : STRING;
s2 : STRING;
s3 : STRING;
s4 : STRING;
iCnt : INT;
END_VAR
iCnt := -1234;
s1 := DINT_TO_DECSTR( iCnt, 1);
s2 := DINT_TO_DECSTR( iCnt, 10 );
iCnt := 0;
s3 := DINT_TO_DECSTR( iCnt, 0 );
iCnt := 1234;
s4 := DINT_TO_DECSTR( iCnt, 10 );
The result:
s1 = '-1234'
s2 = '-0000001234'
s3 = ''
s4 = '0000001234'
Requirements
Development environment | Target system type | PLC libraries to be linked |
---|---|---|
TwinCAT v2.9.0 Build >1021 | PC or CX (x86) | TcUtilities.Lib ( Standard.Lib; TcBase.Lib; TcSystem.Lib are included automatically ) |
TwinCAT v2.10.0 Build >= 1301 | CX (ARM) |