Divide
Divide( value_1, value_2, ... )
Description
The Divide
function computes the quotient of two or more numbers. When
all of the numbers are integers, the result is a
long integer value. When any of the numbers is
a floating-point number, the result is a
double-precision, floating-point value.
Attempting to divide an empty list results in an "invalid argument" error.
Attempting to divide any value by zero results in a "invalid argument" error.
Examples
-
The following query executes two equivalent division operations. The first example provides the
Divide
function a list of numbers. The second equivalent operation first divides 10 by 5, the takes the result of that operation and divides it by 2:Copied!client.query(q.Divide(10, 5, 2)) .then((ret) => console.log(ret))
1
is equivalent to:
Copied!client.query(q.Divide(q.Divide(10, 5), 2)) .then((ret) => console.log(ret))
1
-
The following query demonstrates that dividing with integers results in an integer result:
Copied!client.query(q.Divide(1, 2)) .then((ret) => console.log(ret))
0
-
The following query demonstrates that dividing with a double value results in a floating-point result:
Copied!client.query(q.Divide(1, q.ToDouble(2))) .then((ret) => console.log(ret))
0.5
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!