ToDouble

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

Description

The ToDouble function converts a value to a double-precision numeric value, if possible.

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

Host languages have varying support for double-precision numeric values. Within FaunaDB, double-precision numeric values are stored and operated on as 64-bit, IEEE 754, double-precision float values. The host language you use may affect how the result of ToDouble can be interpreted.

Parameters

Argument Type Definition and Requirements

value

Any

The value to attempt to convert to a double-precision numeric value.

Returns

A double-precision numeric value.

Examples

The following query calls ToDouble multiple times to demonstrate variations on the kinds of values that ToDouble accepts:

System.out.println(
    client.query(
        Arr(
            ToDouble(1234.5678),
            ToDouble(1234),
            ToDouble("123.456789"),
            ToDouble("0not-a-number")
        )
    ).get());
client.query([
  q.ToDouble(1234.5678),
  q.ToDouble(1234),
  q.ToDouble('123.456789'),
  q.ToDouble('0not-a-number'),
])
.then((ret) => console.log(ret))
println(Await.result(
  client.query(
    Arr(
      ToDouble(1234.5678),
      ToDouble(1234),
      ToDouble("123.456789"),
      ToDouble("0not-a-number"),
    )
  ),
  5.seconds
))
Not available in this language yet.
Not available in this language yet.
Not available in this language yet.
Not available in this language yet.
Not available in this language yet.
[1234.5678, 1234.0, 123.456789, 0.0]
[ 1234.5678, 1234, 123.456789, 0 ]
[1234.5678, 1234.0, 123.456789, 0.0]

Was this article helpful?

We're sorry to hear that.
Tell us how we can improve! documentation@fauna.com

Thank you for your feedback!