fromDecimalOrNull

Creates an Integer from the specified text, or returns null if the text doesn't represent an integer.

The text parameter must only contain an optional plus sign (+) or minus sign (-), followed by a sequence of digits (e.g., 1234, +1234, -1234).


Calling from Kotlin

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

// Given
val number = 123456L
val text = "$number"
// When
val result: Integer? = Integer.fromDecimalOrNull(text)
// Then
val expected: Integer = Integer.from(number)
check(result == expected)

This function is not available from Java code, due to its non-explicit support for nullable types.

See the fromDecimal function for throwing an exception instead of returning null in case of invalid text.