toStrictlyPositiveIntOrThrow

@ExperimentalSinceKotoolsTypes(version = "4.4")
fun Number.toStrictlyPositiveIntOrThrow(): StrictlyPositiveInt

Returns this number as a StrictlyPositiveInt, which may involve rounding or truncation, or throws IllegalArgumentException if this number is negative.

Here's some usage examples:

val result: StrictlyPositiveInt = 1.toStrictlyPositiveIntOrThrow()
println(result) // 1

0.toStrictlyPositiveIntOrThrow() // IllegalArgumentException
(-1).toStrictlyPositiveIntOrThrow() // IllegalArgumentException

You can use the toStrictlyPositiveIntOrNull function for returning null instead of throwing an IllegalArgumentException when this number is negative.