Groovy Math.floorDiv
Integer floor division rounds a quotient toward negative infinity.
A simple example
Math.floorDiv
- Start with −7 divided by 3
- Do this Round the quotient down
- Result −3
println(Math.floorDiv(-7, 3))
-3
Syntax
Math.floorDiv(minute, slot)
Run these examples in Groovy
Save one example at a time as Lesson.groovy. Use Groovy 4 on JDK 21.
groovy Lesson.groovyNumber time slots before opening
A shift planner numbers intervals relative to opening time. Assign a time before opening to the correct earlier slot rather than losing the sign at the boundary.
int minute = -7
int slot = 3
println(Math.floorDiv(minute, slot))
-3
Minutes minus nine through minus seven share slot minus three.
Locate an event before opening
A desk groups arrivals into ten-minute blocks, with block zero beginning at opening time. A volunteer arrived one minute before opening and needs the correct block label.
Floor division assigns the minute immediately before zero to block minus one.
Group an afternoon reading
A meter logs one entry per five-minute block starting at noon. A reading comes in seventeen minutes after noon.
Block three covers minutes fifteen through nineteen.
What to watch for
Integer division with the slash operator truncates toward zero on the JVM.