Arithmetic operators
- Operator
- Meaning
- +
- Add
- -
- Minus
- *
- Multiply
- /
- Divide
- %
- Integer divide (divide and return the integer part of the result)
- //
- Remainder (divide and return the remainder--not modulo, because the result might be negative)
- **
- Power (raise a number to a whole-number power)
- Prefix -
- Same as the subtraction:
0 - number
- Prefix +
- Same as the addition:
0 + number
#6
contains a numeric value representing an employee's annual salary, and
the fields
#15
and
#23
contain numeric values representing the employee's annual travel
allowance and annual bonus, respectively, you can select
segments for employees with a combined annual payment
of greater than $100,000 using this comparison:
(#6 + #15 + #23) > 100000
#45
contains the number of sick days an employee is entitled to annually, and
the field
#46
contains the number of sick days an employee has used in the current year,
you can select segments for employees
who have used 50% or more of their sick days entitlement
using this comparison:
(#46 / #45) >= .5
Note that in each of these examples, the arithmetic subexpression is contained in parentheses. This ensures that the entire subexpression is evaluated before the comparison operation.
- Operator
- Meaning
- + - ¬ \
- Prefix operators
- **
- Power
- * /
- Multiply and divide
- + -
- Add and subtract
For example, * (multiply) has a higher priority than + (add),
so
3+2*5
evaluates as
13
(rather than the
25
that would result if strict left to right evaluation occurred).
To force the addition to occur before the multiplication,
you can rewrite the expression as
(3+2)*5.
Adding the parentheses makes the first three tokens a subexpression.