toStrictlyPositiveDoubleOrNull

@ExperimentalSinceKotoolsTypes(version = "4.3.1")
fun Number.toStrictlyPositiveDoubleOrNull(): StrictlyPositiveDouble?

Returns this number as a StrictlyPositiveDouble, which may involve rounding or truncation, or returns null if this number is negative.

var result: StrictlyPositiveDouble? = 1.toStrictlyPositiveDoubleOrNull()
println(result) // 1.0

result = 0.toStrictlyPositiveDoubleOrNull()
println(result) // null

result = (-1).toStrictlyPositiveDoubleOrNull()
println(result) // null

You can use the toStrictlyPositiveDoubleOrThrow function for throwing an IllegalArgumentException instead of returning null.