Boolean conversion
Undefined result if the value range is exceeded If the input value of a type conversion operator is outside the value range of the output data type, the result of the operation is not defined and depends on the platform. This is the case, for example, when a negative operand value is converted from LREAL to the target data type UINT. An exception error is also possible! |
Loss of information possible If a larger data type is converted to a smaller data type, information may be lost. |
String manipulation when converting to STRING or WSTRING With a type conversion to STRING or WSTRING, the typed value is stored as a left aligned string and truncated if it is overlong. Therefore, declare the return variables for the type conversion operators <type>_TO_STRING and <type>_TO_WSTRING long enough to accommodate the string without manipulation. |
<type>_TO_BOOL
The operators are used to convert from another data type to the BOOL data type.
You can specify a variable or a literal as the operand.
Syntax:
<Datentyp>_TO_BOOL (<Variablenname> | <Literal>)
The result is TRUE if the operand is not equal to 0. The result is FALSE if the operand is 0.
With the STRING data type, the result is TRUE if the operand value is 'TRUE' or 'true'. Otherwise, FALSE is returned even if 'True'.
Examples:
ST code | Result |
---|---|
| TRUE |
| FALSE |
| TRUE |
| TRUE |
| TRUE |
| FALSE |
BOOL_TO_<type>
The operators are used to convert the BOOL data type to another data type.
You can specify a variable or a literal as the operand.
Syntax:
BOOL_TO_<Datentyp> (<Variablenname> | <Literal>)
With numerical data types the result is 1 if the operand is TRUE and 0 if the operand is FALSE. With the data type STRING the result is 'TRUE' or 'FALSE'.
Examples:
ST code | Result |
---|---|
| 1 |
| 'TRUE' |
| T#1ms |
| TOD#00:00:00.001 |
| D#1970 |
| DT#1970-01-01-00:00:01 |
FBD code | Result |
---|---|
1 | |
'TRUE' | |
T#1ms | |
TOD#00:00:00.001 | |
D#1970-01-01 |
See also:
- Data types > BOOL