Example: Numeric operators in expressions

These are the examples of numeric operators in expressions.
IMPORTANT:
    • Using strings in numeric operations is not recommended. The exception is the + operator, which is used for string concatenation.
    • Using LINT tags in expressions, write commands, or increment commands is not recommended. This is because the values may lose resolution as a result of performing the expression calculations.
    Ensure that any tag value you use as a divisor cannot at some point have a value of zero. Expressions that attempt to divide a number by zero produce an error at runtime.
Symbol (Operation)
Description
Example: If tag1 = 5 and tag2 = 7, then:
+ (Addition)
Returns the sum of the values. SINT, INT, DINT, LINT, and REAL tags can be used in any order.
All values are converted to double-precision floating point first, and then the operation is performed.
If any operand is a string, it is concatenated.
tag1 + tag2
returns a value of 12
MyDINT + "SomeString"
returns a value of 5SomeString, if MyDINT = 5
- (Subtraction)
Returns the difference of the two values. SINT, INT, DINT, LINT, and REAL tags can be used in any order.
All values are converted to double-precision floating point first, and then the operation is performed.
tag1 - tag2
returns a value of -2
- (Negation)
Inverts the sign of the operand, making a positive number into a negative number or a negative number into a positive number.
-tag2
returns -7
* (Multiplication)
Returns the product of two values. SINT, INT, DINT, LINT, and REAL tags can be used in any order.
All values are converted to double-precision floating point first, and then the operation is performed.
tag1 * tag2
returns a value of 35
/ (Division)
Returns the quotient of the two values. SINT, INT, DINT, LINT, and REAL tags can be used in any order.
All values are converted to double-precision floating point first, and then the operation is performed.
tag1 / tag2
returns a value of 0.71
% (Modulus)
Returns the remainder of one number divided by another. SINT, INT, DINT, LINT, and REAL tags can be used in any order.
All values are converted to double-precision floating point first, and then the operation is performed.
tag1 % tag2
returns a value of 5.
Provide Feedback
Have questions or feedback about this documentation? Please submit your feedback here.
Normal