WMLScript provides all the normal arithmetic operators. The syntax for these is exactly the same as in C or Java.
The simplest two arithmetic operators are unary plus, represented by
+, and unary minus, represented by
. Unary plus simply converts the
value to a number, and unary minus converts the value
to a number, then negates it (subtracts it from zero).
After the unary operators, there are six
binary arithmetic operators.
Addition is represented by
+, subtraction by
, and multiplication by
. There are two division operators:
, which operates on floating-point
numbers and gives a floating-point result, and
, which operates on integers and gives
an integer result. The final operator is the
or remainder operator, which gives the
remainder after integer division and is represented by
All of these, other than
div, should be familiar
to you if you know C or Java. (C and Java use the datatypes of the
operands and the result to determine whether to perform integer or
floating-point division, so there’s no need for the
There’s one slight complication to these operators: as
mentioned in Operand Conversions earlier
in this chapter, the
+ operator performs string
concatenation rather than addition if either of its operands is a
string. This can introduce subtle problems.