int()
Converts a string to an integer.
Syntax
int(EXPR)
Required Parameter
EXPR
- Expression that returns a string to be converted to an integer. The argument must be one of a string, double, float, IP address, or array.
Description
When evaluating an expression, it works as follows:
- When the value of the expression is
null
, this function returnsnull
. - Even when a string cannot be converted to an integer, this function also returns
null
. - When the value of the expression is an array, this function converts each element of the array to an integer.
- If any other type is passed as an argument, this function performs an automatic conversion and then converts it to an integer.
Usage
json "{}" | eval numbers=int("1234") => 1234
json "{}" | eval numbers=int(1234) => 1234
json "{}" | eval numbers=int(ip("0.0.0.1")) => 1
json "{}" | eval numbers=int(ip("192.168.0.1")) => -1062731775
json "{}" | eval numbers=int(12345.6789) => 12345
json "{}" | eval numbers=int(null) => null
json "{}" | eval numbers=int("invalid") => null
json "{}" | eval numbers=int(array("1", "abc", "2", 3, array(4)))
=> [1, null, 2, 3, null]