mod
Description
Returns the remainder after dividing a number by a divisor.
Equivalent to the modulus operator (%).
Syntax
Like many functions in DataPrime, mod supports two notations, function and method. These interchangeable forms allow flexibility in how you structure expressions.
- Function notation
- Method notation
mod(number: number, divisor: number): number
(number: number).mod(divisor: number): number
Arguments
| Name | Type | Required | Description |
|---|---|---|---|
number | number | true | The value to divide |
divisor | number | true | The divisor used for the modulus operation |
Example
Use case: Determine if a number is even or odd
A value is even if dividing it by 2 leaves a remainder of 0. Otherwise, it is odd.
Example data
{
"val": 7
},
{
"val": 12
}
Example query
- Function notation
- Method notation
create is_even from (mod(val, 2) == 0)
create is_even from (val.mod(2) == 0)
Example output
{
"val": 7,
"is_even": false
},
{
"val": 12,
"is_even": true
}