TRY_DIVIDE
All functions > MATH > TRY_DIVIDE
Returns the result of the division of the first number by the second as a double. Returns NULL if the divisor is zero.
Signatures
Safe numeric division
Returns: Result of the division as a double, or NULL if divisor is zero
TRY_DIVIDE(dividend: T, divisor: T) → DOUBLE sql
| Parameter | Type | Required | Description |
|---|---|---|---|
dividend | T | Yes | Number to be divided |
divisor | T | Yes | Number to divide by |
Notes
- Both arguments are cast to DOUBLE before division
- Returns NULL if either operand is NULL
- Returns NULL if the divisor is zero (instead of raising an error)
- Result is always a floating-point number, even for integer inputs
- Safe alternative to DIVIDE when the divisor may be zero
See also
Examples
FeatureQL
SELECT
f1 := TRY_DIVIDE(10e0, 3e0), -- Division with remainder
f2 := TRY_DIVIDE(15e0, 5e0), -- Exact division
f3 := TRY_DIVIDE(42e0, 0e0), -- Division by zero returns NULL
f4 := TRY_DIVIDE(-8e0, 4e0) -- Negative division
;Result
| f1 VARCHAR | f2 VARCHAR | f3 VARCHAR | f4 VARCHAR |
|---|---|---|---|
| 3.3333333333333335 | 3.0 | NULL | -2.0 |
On this page