create

@ExperimentalSince(version = KotoolsTypesVersion.V4_5_0)
fun create(number: Number): NonZeroInt

Creates a NonZeroInt from the specified number, which may involve rounding or truncation, or throws an IllegalArgumentException if the number equals zero.


Calling from Kotlin

Here's an example of calling this function from Kotlin code:

val number: NonZeroInt = NonZeroInt.create(23)
println(number) // 23

Calling from Java

Here's an example of calling this function from Java code:

final NonZeroInt number = NonZeroInt.Companion.create(23);
System.out.println(number); // 23

You can use the NonZeroInt.Companion.createOrNull function for returning null instead of throwing an exception in case of invalid number.