Operators and expressions
The arithmetic operators are:
Operator | Operation |
---|---|
+ | Addition |
- | Subtraction |
* | Multiplication |
/ | Division |
% | Modulo |
In an arithmetic expression the terms are evaluated left to right.
The order of precedence of the operators is: *, /, %, +, -. For example,
the result of :
4 * 2 + 16 / 8 - 1 * 2
is 8. You can use
parentheses to indicate the order in which you want expressions to
be evaluated:
(4 * 2) + (16 / 8) - (1 * 2) evaluates to 8
but
4 * (( 2 + 16) / (8 - 1)) * 2 evaluates to 20.571