Converts the specified object to Integer according to the rules:
obj
is already a Integer object
(an instance of java.lang.Integer
),
the function works simply as a type cast operator,
same as it would be in Java: (Integer) obj
obj
is any other Number object
(an instance of java.lang.Number
),
the function returns:new Integer(((Number) obj).intValue())
obj
is a Boolean object
(i.e. an instance of java.lang.Boolean
),
the function returns the same values as the
expression: obj.toBoolean() ? 1 : 0
obj
is not null
, the function tries to parse the
string returned by obj.toString()
call as integer, fixed-point or
floating-point decimal number value.
value
,
the function returns: new Integer((int) value)
obj
parameter is null
, the function returns 0
.
Examples:
Tip:toInt(2) == 2 toInt(3.4) == 3 toInt("-3.4") == -3 toInt(true) == 1 toInt(false) == 0
You may call this function in a more method-like style:
obj.toInt()