createOrNull

@ExperimentalSince(version = KotoolsTypesVersion.V4_5_0)
fun createOrNull(number: Number): PositiveInt?

Creates a PositiveInt from the specified number, which may involve rounding or truncation, or returns null if the number is less than zero.


Calling from Kotlin

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

val number: PositiveInt? = PositiveInt.createOrNull(23)
println(number) // 23

Calling from Java

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

final PositiveInt number = PositiveInt.Companion.createOrNull(23);
System.out.println(number); // 23

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