Cypher toInteger Function

toInteger() converts a floating point or string value to an integer value.

Syntax: toInteger(expression)

Returns: An Integer.

Arguments

NameDescription
expressionAn expression that returns a numeric or string value.

Example

RETURN toFloat("8")

The value returned will be a Integer after converting the expression into a Integer. In this case, “8” will be converted to a Integer and 8 will be returned.

Note-“8” is not the same as 8. 8 is an Integer whereas “8” is a string.

Considerations

  • toInteger(null) returns null.
  • If expression is an integer value, it will be returned unchanged.
  • If the parsing fails, null will be returned.

Example

RETURN toInteger("12")

Returns the following Result

toInteger("12")
12

Example

RETURN toInteger("12.0")

Returns the following Result

toInteger("12.0")
12

Example

RETURN toInteger(12.4)

Returns the following Result

toInteger(12.4)
12

Example

RETURN toInteger("Some Random String")

Returns the following Result

toInteger("Some Random String")
null

Note– If the String does not contain a float or an integer value, null is returned.

Example

RETURN toInteger(TRUE)

Returns the following Result

toInteger(TRUE)
ERROR Neo.ClientError.Statement.SyntaxError

Note– If the result is not a String or a numeric value, an error is raised.

Example

RETURN toInteger(null)

Returns the following Result

toInteger("Some Random String")
null

Learn More