Arithmetic Operators
You can use the following operators for numeric data types, such as byte, short, int, long, double, decimal, and float.
Arithmetic Operator | Description | Simple Expression | Result |
---|---|---|---|
+ |
Addition |
2+8 |
10 |
- |
Subtraction |
7-4 |
3 |
* |
Multiplication |
3*4 |
12 |
/ |
Division |
3/2 |
1.5 |
% |
Remainder |
3%2 |
1 |
== |
Equals |
12 == 13 |
false |
!= |
Not Equals |
12 != 13 |
true |
> |
Greater than |
15 > 16 |
false |
>= |
Greater than or Equals |
15 >= 15 |
true |
< |
Less than |
12 < 10 |
false |
<= |
Less than or Equals |
12 <= 12 |
true |
abs |
Returns the absolute value of a number |
abs(-6) |
6 |
In addition, you can also use the following operators on non-integer data types, such as double, decimal, and float.
Arithmetic Operator | Description | Simple Expression | Result |
---|---|---|---|
floor |
Returns the largest (closest to positive infinity) number that is not greater than the argument and that is an integer. |
floor(5.60) |
5 |
ceil |
Returns the smallest (closest to negative infinity) number that is not less than the argument and that is an integer. |
ceil(5.60) |
6 |
round |
Returns the number that is closest to the argument and that is an integer. |
round(5.60) |
6 |