createOrNull
Creates a StrictlyNegativeDouble from the specified number, which may involve rounding or truncation, or returns null
if the number is greater than or equals zero.
Calling from Kotlin
Here's an example of calling this function from Kotlin code:
val number: Number = Random.nextInt(Int.MIN_VALUE until 0)
val result: StrictlyNegativeDouble? =
StrictlyNegativeDouble.createOrNull(number)
println(result != null) // true
Content copied to clipboard
Calling from Java
Here's an example of calling this function from Java code:
final Random random = new Random();
final Number number = random.nextInt(Integer.MIN_VALUE, 0);
final StrictlyNegativeDouble result =
StrictlyNegativeDouble.Companion.createOrNull(number);
System.out.println(result != null); // true
Content copied to clipboard
You can use the StrictlyNegativeDouble.Companion.create function for throwing an exception instead of returning null
in case of invalid number.