toNonZeroIntOrThrow

@ExperimentalSinceKotoolsTypes(version = "4.3.1")
fun Number.toNonZeroIntOrThrow(): NonZeroInt

Returns this number as a NonZeroInt, which may involve rounding or truncation, or throws IllegalArgumentException if this number equals zero.

var result: NonZeroInt = 1.toNonZeroIntOrThrow()
println(result) // 1

0.toNonZeroIntOrThrow() // IllegalArgumentException

You can use the toNonZeroIntOrNull function for returning null instead of throwing an IllegalArgumentException when this number equals zero.