roundToInt

actual fun Double.roundToInt(): Int (source)

Platform and version requirements: Kotlin 1.2

Rounds this Double value to the nearest integer and converts the result to Int. Ties are rounded towards positive infinity.

Special cases:

  • x.roundToInt() == Int.MAX_VALUE when x > Int.MAX_VALUE
  • x.roundToInt() == Int.MIN_VALUE when x < Int.MIN_VALUE

Exceptions

IllegalArgumentException - when this value is NaN

actual fun Float.roundToInt(): Int (source)

Platform and version requirements: Kotlin 1.2

Rounds this Float value to the nearest integer and converts the result to Int. Ties are rounded towards positive infinity.

Special cases:

  • x.roundToInt() == Int.MAX_VALUE when x > Int.MAX_VALUE
  • x.roundToInt() == Int.MIN_VALUE when x < Int.MIN_VALUE

Exceptions

IllegalArgumentException - when this value is NaN