floor()#
relationalai.std.math
#floor(number: Number | Producer) -> Expression
Calculates the floor of a number. The floor of a number is the largest integer less than or equal to the number. Must be called in a rule or query context.
Parameters#
Name | Type | Description |
---|---|---|
number | Number or Producer | The number to take the floor of. |
Returns#
An Expression
object.
Example#
#import relationalai as rai
from relationalai.std import alias
from relationalai.std.math import floor
# 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.9)
# What is each person's height rounded down to the nearest whole number?
with model.query() as select:
p = Person()
height_rounded = floor(p.height_cm)
response = select(p.name, alias(height_rounded, "height_rounded"))
print(response.results)
# Output:
# name height_rounded
# 0 Alice 170.0
# 1 Bob 180.0
For negative numbers, the result is rounded towards negative infinity:
#with model.query() as select:
response = select(floor(-5.5))
print(response.results)
# Output:
# v
# 0 -6.0