toFloat()
converts an integer or string value to a floating point number.
Syntax: toFloat(expression)
Returns: A Float.
Arguments
Name | Description |
expression | An expression that returns a numeric or string value. |
Example
RETURN toFloat("8.7")
The value returned will be a Float after converting the expression into a Float. In this case, “8.7” will be converted to a Float and 8.7 will be returned.
Note-“8.7” is not the same as 8.7. 8.7 is a Float whereas “8.7” is a string.
Considerations
toFloat(null)
returnsnull
.- If
expression
is a floating point number, it will be returned unchanged. - If the parsing fails,
null
will be returned.
Example
RETURN toFloat("12")
Returns the following Result
toFloat("12") |
12.0 |
Example
RETURN toFloat(12)
Returns the following Result
toFloat(12) |
12.0 |
Example
RETURN toFloat(12.4)
Returns the following Result
toFloat(12.4) |
12.4 |
Example
RETURN toFloat("Some Random String")
Returns the following Result
toFloat("Some Random String") |
null |
Note– If the String does not contain a float or an integer value, null is returned.
Example
RETURN toFloat(TRUE)
Returns the following Result
toFloat(TRUE) |
ERROR Neo.ClientError.Statement.SyntaxError |
Note– If the result is not a String or an Integer, an error is raised.
Example
RETURN toFloat(null)
Returns the following Result
toFloat("Some Random String") |
null |