isMultipleOf method

bool isMultipleOf(
  1. double other
)

Returns true if this double is a multiple of other

Note: Due to floating-point precision, this may not behave as expected for all values. Consider using isCloseTo for floating-point comparisons.

Example:

10.0.isMultipleOf(5.0); // true
11.0.isMultipleOf(5.0); // false
0.0.isMultipleOf(5.0);  // true (0 is a multiple of any number)

Throws:

  • ArgumentError: If other is zero

Implementation

bool isMultipleOf(double other) {
  if (other == 0) {
    throw ArgumentError('Cannot check if a number is a multiple of zero');
  }
  return (this % other) == 0;
}