floorDiv
Divides this value by the other value, flooring the result to an integer that is closer to negative infinity.
Since Kotlin
1.5Samples
import kotlin.test.assertFailsWith
fun main() {
//sampleStart
// Regular integer division (/) truncates toward zero
println((-7) / 3) // -2
// floorDiv rounds toward negative infinity
println((-7).floorDiv(3)) // -3
println(7.floorDiv(3)) // 2
println(7.floorDiv(-3)) // -3
// Dividing by zero throws, just like the / operator
// 1.floorDiv(0) // will fail with ArithmeticException
//sampleEnd
}Content copied to clipboard