roundTo method

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

Rounds this to the closest multiple of factor.

The returned int may overflow or underflow if sufficiently large or small.

Contract

Throws RangeError if factor <= 0.

Example

12.roundTo(10); // 10

22.roundTo(10); // 20

25.roundTo(10) // 30

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

Implementation

@Possible({RangeError})
@useResult int roundTo(int factor) => this % factor >= (factor.toDouble() / 2) ? ceilTo(factor) : floorTo(factor);