Math クラス
算術演算のメソッドが含まれます。
名前空間
Math のメソッド
Math のメソッドは次のとおりです。すべてのメソッドが静的です。
mod(integerValue1, integerValue2)
integerValue1 を integerValue2 で除算した余りを返します。
署名
public static Integer mod(Integer integerValue1, Integer integerValue2)
戻り値
型: Integer
例
1Integer remainder = math.mod(12, 2);
2system.assertEquals(remainder, 0);
3
4Integer remainder2 = math.mod(8, 3);
5system.assertEquals(remainder2, 2);round(decimalValue)
decimal の丸められた近似値を返します。数値は、均等丸めモードを使用して、「最も近い近似値」である整数に丸められます。ただし、両方の近似値が等距離にある場合は、このモードでは偶数の近似値に丸められます。
署名
public static Integer round(Decimal decimalValue)
パラメータ
- decimalValue
- 型: Decimal
戻り値
型: Integer
使用方法
この丸めモードは、連続する計算に対して繰り返し適用される場合、統計的に累積エラーを最小化します。
例
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)
decimal の丸められた近似値を返します。数値は、均等丸めモードを使用して、「最も近い近似値」である整数に丸められます。ただし、両方の近似値が等距離にある場合は、このモードでは偶数の近似値に丸められます。
署名
public static Long roundToLong(Decimal decimalValue)
パラメータ
- decimalValue
- 型: Decimal
戻り値
型: Long
使用方法
この丸めモードは、連続する計算に対して繰り返し適用される場合、統計的に累積エラーを最小化します。
例
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);