% [remainder]
All functions > MATH > % [remainder]
Returns the remainder after dividing the left-hand number by the right-hand number.
Syntax
left % right · MODULO(left, right) · MOD(left, right)
Function form
Modulo: Remainder of the division
MODULO(dividend: T, divisor: T) → T sql
| Parameter | Type | Required | Description |
|---|---|---|---|
dividend | T | Yes | Number to be divided |
divisor | T | Yes | Number to divide by |
With:
T: Custom types: TINYINT | SMALLINT | INT | BIGINT | DECIMALBoth arguments must be of the same type (integer or DECIMAL)
Sign of the result matches the sign of the dividend
Returns NULL if either operand is NULL
Division by zero raises an error
Aliases: MOD
Notes
- Supported for integer and DECIMAL types; both operands must be the same type
- The result has the same type as the operands; its sign follows the dividend
- Returns NULL if either operand is NULL
- Division by zero is an error
Examples
Modulo - remainder
FeatureQL
RETURN
-- Basic modulo
f1 := 10 % 3,
-- Non-zero remainder
f2 := 15 % 4
;Result
| f1 BIGINT | f2 BIGINT |
|---|---|
| 1 | 3 |
Modulo - edge cases
FeatureQL
RETURN
-- Sign follows dividend
f1 := -10 % 3,
-- No remainder
f2 := 7 % 7
;Result
| f1 BIGINT | f2 BIGINT |
|---|---|
| -1 | 0 |
MODULO(...)
FeatureQL
RETURN
-- Function call
f1 := MODULO(10, 3)
;Result
| f1 BIGINT |
|---|
| 1 |
.MODULO(...) — chained
FeatureQL
RETURN
-- Integer literal: parenthesize for `.MODULO` on BIGINT
f1 := (10).MODULO(3),
-- Decimal base: chain without extra parentheses
f2 := 10.0.MODULO(3)
;Result
| f1 BIGINT | f2 DECIMAL |
|---|---|
| 1 | 1.0 |
MODULO — Edge cases
FeatureQL
RETURN
-- Another remainder
f1 := MODULO(15, 4),
-- No remainder
f2 := MODULO(7, 7),
-- Negative dividend
f3 := MODULO(-10, 3)
;Result
| f1 BIGINT | f2 BIGINT | f3 BIGINT |
|---|---|---|
| 3 | 0 | -1 |