ceilTo method

  1. @Possible({RangeError})
  2. @useResult
int ceilTo(
  1. int factor
)

Ceils this to the closest multiple of factor.

The returned int may overflow if sufficiently large.

Contract

Throws RangeError if factor <= 0.

Example

12.ceilTo(10); // 20

22.ceilTo(10); // 30

25.ceilTo(10) // 30

25.ceilTo(-5); // throws RangeError

Implementation

@Possible({RangeError})
@useResult int ceilTo(int factor) {
  if (factor < 1) {
    throw RangeError.range(factor, 1, null, 'factor');
  }

  final sum = this + factor - 1;
  return sum - (sum % factor);
}