Operators
You can use operators to manipulate values in an expression. The following operators are available in the Template scripting language.
Operator |
Operand |
Result |
Operation |
Example |
---|---|---|---|---|
(...) |
(...) |
... |
Grouping |
((i + 1) * 3) |
+ |
+NUMBER |
NUMBER |
Positive (monadic) |
+4 |
- |
-NUMBER |
NUMBER |
Negative (monadic) |
-4 |
+
|
NUMBER + NUMBER |
NUMBER |
Addition |
i + 1 |
TEXT+TEXT |
TEXT |
Concatenation |
line + "." |
|
- |
NUMBER - NUMBER |
NUMBER |
Subtraction |
amount - fee |
* |
NUMBER * NUMBER |
NUMBER |
Multiplication |
years * 365 |
/ |
NUMBER / NUMBER |
NUMBER |
Division |
bottles / 12 |
% |
NUMBER % NUMBER |
NUMBER |
Percentage |
price % 21 |
<
|
NUMBER < NUMBER |
BOOL |
Less than |
age < 21 |
TEXT < TEXT |
BOOL |
Sorts before |
class < "D" |
|
<=
|
NUMBER <= NUMBER |
BOOL |
Less than or equal |
age <= 21 |
TEXT <= TEXT |
BOOL |
Equal or sorts before |
class <= "D" |
|
>
|
NUMBER > NUMBER |
BOOL |
Greater than |
age > 21 |
TEXT > TEXT |
BOOL |
Sorts after |
class > "D" |
|
>=
|
NUMBER >= NUMBER |
BOOL |
Greater than or equal |
age >= 21 |
TEXT >= TEXT |
BOOL |
Equal or sorts after |
class >= "D" |
|
=
|
NUMBER = NUMBER |
BOOL |
Equals |
age = 21 |
BOOL = BOOL |
BOOL |
Equals |
paid = FALSE |
|
TEXT = TEXT |
BOOL |
Equals |
class = "D" |
|
<>
|
NUMBER <> NUMBER |
BOOL |
Not equal |
age <> 18 |
BOOL <> BOOL |
BOOL |
Not equal |
paid <> shipped |
|
TEXT <> TEXT |
BOOL |
Not equal |
class <> "D" |
|
NOT |
NOT BOOL |
BOOL |
Logical negation |
NOT paid |
AND |
BOOL AND BOOL |
BOOL |
Logical AND |
trained AND licensed |
OR |
BOOL OR BOOL |
BOOL |
Logical OR |
shipped OR cancelled |
Operators in an expression are evaluated based on their priority from top to bottom:
- ( )
- Monadic +, monadic -, NOT
- *, /, %
- +, -
- <=, <, >, >=
- =, <>
- AND
- OR
Examples are provided here.
1 + 2 * -3 equals to -5
(1 + 2) * -3 equals to - 9
The operators +, -, *, /, and % can be combined with the ASSIGN statement to modify a variable:
ASSIGN <variable> <op>:= <expression>
This example is a shorthand for:
ASSIGN <variable> := <variable> <op> <expression>
Examples are provided here.
ASSIGN counter +:= 1
ASSIGN line +:= “, “ + item
The AND operator always calculates both operands. The operator evaluates to TRUE if both operands are TRUE, and FALSE if either operand is FALSE.
The OR operator always calculates both operands. The operator evaluates to TRUE if either operand is TRUE, and FALSE if both operands are FALSE.
The EnhancedUnicodeSupport setting in KCM Core Administrator affects TEXT comparisons. Comparisons are based on the compare_characters function, which is Unicode aware and handles word processor layout intelligently. If this setting is disabled, a literal comparison is used that might give unexpected results. For more information on the function compare_characters, see compare_characters.