Math operators in apex
To manipulate numeric data, apex supports math operators. Following are the math operators in apex:
- AdditionAdds two numbers together. Integer x = 5; Integer y = 3; Integer result = x + y; // result is 8
- SubtractionSubtracts the second number from the first. Integer x = 5; Integer y = 3; Integer result = x - y; // result is 2
- MultiplicationMultiplies two numbers. Integer x = 5; Integer y = 3; Integer result = x * y; // result is 15
- DivisionDivides the first number by the second. Integer x = 6; Integer y = 3; Integer result = x / y; // result is 2
Apart from math operators, apex provides a set of math functions which can be used to perform math operations
The following code snippet shows how to add two numbers in apex.
Loading...
In the above example:
- The variables numb1, numb2 are Integervariables.
- The variable sumstore the sum of numb1, numb2.
Try It Yourself
Loading...