Math Class
Namespace
Math Fields
The following are fields for Math.
PI
Signature
public static final Double PI
Property Value
Type: Double
Math Methods
The following are methods for Math. All methods are static.
atan2(xCoordinate, yCoordinate)
Signature
public static Decimal atan2(Decimal xCoordinate, Decimal yCoordinate)
Return Value
Type: Decimal
atan2(xCoordinate, yCoordinate)
Signature
public static Double atan2(Double xCoordinate, Double yCoordinate)
Return Value
Type: Double
max(decimalValue1, decimalValue2)
Signature
public static Decimal max(Decimal decimalValue1, Decimal decimalValue2)
Return Value
Type: Decimal
Example
1Decimal larger = math.max(12.3, 156.6);
2system.assertEquals(larger, 156.6);min(decimalValue1, decimalValue2)
Signature
public static Decimal min(Decimal decimalValue1, Decimal decimalValue2)
Return Value
Type: Decimal
Example
1Decimal smaller = math.min(12.3, 156.6);
2system.assertEquals(smaller, 12.3);mod(integerValue1, integerValue2)
Signature
public static Integer mod(Integer integerValue1, Integer integerValue2)
Return Value
Type: Integer
Example
1Integer remainder = math.mod(12, 2);
2system.assertEquals(remainder, 0);
3
4Integer remainder2 = math.mod(8, 3);
5system.assertEquals(remainder2, 2);random()
Signature
public static Double random()
Return Value
Type: Double
round(doubleValue)
Signature
public static Integer round(Double doubleValue)
Parameters
- doubleValue
- Type: Double
Return Value
Type: Integer
round(decimalValue)
Signature
public static Integer round(Decimal decimalValue)
Parameters
- decimalValue
- Type: Decimal
Return Value
Type: Integer
Usage
Note that this rounding mode statistically minimizes cumulative error when applied repeatedly over a sequence of calculations.
Example
1Decimal d1 = 4.5;
2Integer i1 = Math.round(d1);
3System.assertEquals(4, i1);
4
5Decimal d2 = 5.5;
6Integer i2 = Math.round(d2);
7System.assertEquals(6, i2);roundToLong(decimalValue)
Signature
public static Long roundToLong(Decimal decimalValue)
Parameters
- decimalValue
- Type: Decimal
Return Value
Type: Long
Usage
Note that this rounding mode statistically minimizes cumulative error when applied repeatedly over a sequence of calculations.
Example
1Decimal d1 = 4.5;
2Long i1 = Math.roundToLong(d1);
3System.assertEquals(4, i1);
4
5Decimal d2 = 5.5;
6Long i2 = Math.roundToLong(d2);
7System.assertEquals(6, i2);tanh(decimalAngle)
Signature
public static Decimal tanh(Decimal decimalAngle)
Parameters
- decimalAngle
- Type: Decimal
Return Value
Type: Decimal
tanh(doubleAngle)
Signature
public static Double tanh(Double doubleAngle)
Parameters
- doubleAngle
- Type: Double
Return Value
Type: Double