roundToNearestMultiple method

num roundToNearestMultiple(
  1. num multiple
)

Rounds this number to the nearest multiple of multiple.

Throws ArgumentError if multiple is zero.

Implementation

num roundToNearestMultiple(num multiple) {
  if (multiple == 0) {
    throw ArgumentError('Multiple cannot be zero.');
  }
  return (this / multiple).round() * multiple;
}