FQL v4 will be decommissioned on June 30, 2025. Ensure that you complete your migration from FQL v4 to FQL v10 by that date.

Fauna accounts created after August 21, 2024 must use FQL v10. These accounts will not be able to run FQL v4 queries or access the v4 Dashboard.

For more details, see the v4 EOL announcement and migration guide. Contact support@fauna.com with any questions.

ToDouble

This reference topic applies to FQL v4. Go to this page for the latest FQL v10 reference topics.

ToDouble( value )
to_double( value )
ToDouble( value )
ToDouble( value )
ToDouble( value )
ToDouble( value )

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 Fauna, 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

Parameter 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:

client.query(
  [
    q.ToDouble(1234.5678),
    q.ToDouble(1234),
    q.ToDouble('123.456789'),
    q.ToDouble('0not-a-number'),
  ]
)
.then((ret) => console.log(ret))
.catch((err) => console.error(
  'Error: [%s] %s: %s',
  err.name,
  err.message,
  err.errors()[0].description,
))
[ 1234.5678, 1234, 123.456789, 0 ]
result = client.query(
  [
    q.to_double(1234.5678),
    q.to_double(1234),
    q.to_double('123.456789'),
    q.to_double('0not-a-number'),
  ]
)
print(result)
[1234.5678, 1234.0, 123.456789, 0.0]
result, err := client.Query(
	f.Arr{
		f.ToDouble(1234.5678),
		f.ToDouble(1234),
		f.ToDouble("123.456789"),
		f.ToDouble("0not-a-number"),
	})

if err != nil {
	fmt.Fprintln(os.Stderr, err)
} else {
	fmt.Println(result)
}
[1234.5678 1234 123.456789 0]
try
{
    Value result = await client.Query(
        Arr(
            ToDouble(1234.5678),
            ToDouble(1234),
            ToDouble("123.456789"),
            ToDouble("0not-a-number")
        )
    );

    Console.WriteLine(result);
}
catch (Exception e)
{
    Console.WriteLine($"ERROR: {e.Message}");
}
Arr(DoubleV(1234.5678), DoubleV(1234), DoubleV(123.456789), DoubleV(0))
System.out.println(
    client.query(
        Arr(
            ToDouble(1234.5678),
            ToDouble(1234),
            ToDouble("123.456789"),
            ToDouble("0not-a-number")
        )
    ).get());
[1234.5678, 1234.0, 123.456789, 0.0]
[
  ToDouble(1234.5678),
  ToDouble(1234),
  ToDouble('123.456789'),
  ToDouble('0not-a-number'),
]
[ 1234.5678, 1234, 123.456789, 0 ]
Query metrics:
  •    bytesIn: 101

  •   bytesOut:  46

  • computeOps:   1

  •    readOps:   0

  •   writeOps:   0

  •  readBytes:   0

  • writeBytes:   0

  •  queryTime: 2ms

  •    retries:   0

Is this article helpful? 

Tell Fauna how the article can be improved:
Visit Fauna's forums or email docs@fauna.com

Thank you for your feedback!