toStrictlyPositiveDoubleOrNull
@ExperimentalSinceKotoolsTypes(version = "4.3.1")
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
Content copied to clipboard
You can use the toStrictlyPositiveDoubleOrThrow function for throwing an IllegalArgumentException instead of returning null
.