floor
is a mathematics primitive that reports the closest integer below a given number. In other words, it rounds the number down. For example, floor 5.2
would report 5, and floor -4.8
would report -5.
In the model example below, each turtle has a my-money
variable that increases or decreases a little bit at each tick. We use the floor
primitive to round up a turtle's my-money
variable because we want to present a label under each turtle showing their current money. If we do not round this variable either up or down, their labels would show many floating point numbers such as 1.822882372836
, which would be visually unpleasant. We also use the floor
primitive in setting each turtle's ycor
parameter so that the turtles move only when the rounded-up version of their my-money
variable changes. If they make or lose just a little bit of money, they remain stationary. Lastly, we use the floor
, and its opposite ceiling
, for two of our three monitors in the interface.
Once you mastered the floor
primitive, don't stop there. Check out the resources below to improve your NetLogo skills.
floor
primitive: