Notes
Math Methods
Math.max(x,y)
The Math.max(x,y)
method can be used to find the highest value of x and y:
System.debug(Math.max(12, 15));
Output: 15
Math.min(x,y)
The Math.min(x,y)
method can be used to find the smallest value of x and y:
System.debug(Math.min(12, 15));
Output: 12
Math.sqrt(x)
The Math.sqrt(x)
method returns the square root of x:
System.debug(Math.sqrt(64));
Output: 8.0
Math.abs(x)
The Math.abs(x)
method returns the absolute (positive) value of x:
System.debug(Math.abs(-3.4));
Output: 3.4
Random Numbers
Math.random()
returns a random number between 0.0 (inclusive), and 1.0 (exclusive):
System.debug(Math.random());
Math.mod(x,y)
The Math.mod(x,y) method returns the division remainder when x is divided by y:
System.debug(Math.mod(12,5));
Output: 2
Note: Other methods will be studied in future.