trunc_divide()#

relationalai.std.math
#trunc_divide(numerator: Number | Producer, denominator: Number | Producer) -> Expression

Calculates the division of numerator by denominator, rounded towards zero. The result is of the same type as the numerator. Must be called in a rule or query context.

Parameters#

NameTypeDescription
numeratorNumber or ProducerThe numerator of the division.
denominatorNumber or ProducerThe denominator of the division.

Returns#

An Expression object.

Example#

#import relationalai as rai
from relationalai.std import alias
from relationalai.std.math import trunc_divide

# Create a model with a `Person` type.
model = rai.Model("people")
Person = model.Type("Person")

# Add some people to the model.
with model.rule():
    Person.add(name="Alice", height_cm=170.1)
    Person.add(name="Bob", height_cm=180)

# What is each person's height rounded down to the nearest whole number?
with model.query() as select:
    p = Person()
    half_height = trunc_divide(p.height_cm, 2)
    response = select(p.name, alias(half_height, "half_height"))

print(response.results)
# Output:
#     name  half_height
# 0  Alice         85.0
# 1    Bob         90.0

See Also#