num_to_string
Inputs
Input |
Data Type |
Range |
Unit |
Default |
Description |
---|---|---|---|---|---|
IN |
ANY |
|
|
|
Input number. |
Width |
DINT |
|
|
|
Length of the output string. |
Digits |
DINT |
|
|
|
Number of digits after decimal point. |
Outputs
Output |
Data Type |
Range |
Unit |
Description |
---|---|---|---|---|
Q |
STRING |
|
|
Value converted to string. |
Remarks
This function converts any numerical value to a string.
It allows a specific length and a number of digits after the decimal points.
-
If WIDTH is 0 (zero), the string is formatted with the necessary length.
Q := NUM_TO_STRING (1.333333, 0, 2); (* Q is '1.33' *)
-
If WIDTH is greater than 0 (zero), the string is completed with leading blank characters in order to match the value of WIDTH.
Q := NUM_TO_STRING (123.4, 8, 2); (* Q is ' 123.40' *)
-
If WIDTH is greater than 0 (zero), the string is completed with trailing blank characters in order to match the value of WIDTH.
Q := NUM_TO_STRING (123.4, -8, 2); (* Q is '123.40 ' *)
-
If DIGITS is 0 (zero) then neither decimal part nor decimal point are added.
Q := NUM_TO_STRING (1.333333, 3, 0); (* Q is ' 1' *)
-
If DIGITS is greater than 0 (zero), the corresponding number of decimal digits are added. '0' digits are added if necessary
Q := NUM_TO_STRING (1.333333, 0, 1); (* Q is '1.3' *)
-
If the value is too long for the specified width, the string is filled with '*' characters.
Q := NUM_TO_STRING (1234, 3, 0); (* Q is '***' *)