ToInteger

ToInteger( value )
Not available in this language yet.
Not available in this language yet.
ToInteger( value )
Not available in this language yet.
ToInteger( value )

Description

The ToInteger function converts a value to a numeric integer, if possible.

Attempting to convert a value to a number which has no numeric representation results in an "invalid argument" error.

Parameters

Argument Type Definition and Requirements

value

Any

The value to attempt to convert to an integer.

Returns

The integer that corresponds to value.

Examples

The following query uses ToInteger multiple times to demonstrate how the function converts various kinds of values into integers:

System.out.println(
    client.query(
        Arr(
            ToInteger(Value(1234.5678)),
            ToInteger(Value(1234)),
            ToInteger(Value("123"))
        )
    ).get());
Not available in this language yet.
client.query([
  q.ToInteger(1234.5678),
  q.ToInteger(1234),
  q.ToInteger('123'),
]).then((ret) => console.log(ret))
Not available in this language yet.
println(Await.result(
  client.query(
    Arr(
      ToInteger(1234.5678),
      ToInteger(1234),
      ToInteger("123")
    )
  ),
  5.seconds
))
Not available in this language yet.
[1234, 1234, 123]
[ 1234, 1234, 123 ]
[1234, 1234, 123]

Was this article helpful?

We're sorry to hear that.
Tell us how we can improve!
Visit Fauna's Discourse forums or email docs@fauna.com

Thank you for your feedback!