is there a better way to divide ints and round dow...

# announcementsb

Bernhard

11/19/2020, 9:39 AMis there a better way to divide ints and round down to an int than this

Copy code

`floor(int1.toDouble() / int2).toInt()`

v

Vampire

11/19/2020, 9:48 AMWhy don't you simply do an integer division?

`int1 / int2`

Vampire

11/19/2020, 9:49 AM Copy code

```
fun main() {
val three: Int = 3
val two: Int = 2
println(three / two)
}
```

results in printing `1`

r

Rob Elliot

11/19/2020, 9:51 AMJust to be clear, int division always rounds down:

`9/5 == 1`

b

Bernhard

11/19/2020, 9:59 AMthanks, types required in floor probably confused me

Bernhard

11/19/2020, 10:00 AMand I wasn’t sure if there was something like / and // in python

v

Vampire

11/19/2020, 10:00 AMYou mean **@Rob Elliot** , but there indeed is a difference, the snippet of Bernhard gives

`-1`

I guess `-2`

Vampire

11/19/2020, 10:00 AMWhat do

`/`

and `//`

in Python do?r

Rob Elliot

11/19/2020, 10:01 AMI’d left a space after the hyphen, but I’ve clarified it now

v

Vampire

11/19/2020, 10:03 AMWell, for negative numbers it is indeed different.
Original snippet with

`floor`

always rounds towards negative infinity.
Pure integer division always rounds towards `0`

r

Rob Elliot

11/19/2020, 10:04 AMGood point, big difference.

v

Vampire

11/19/2020, 10:05 AMAnd also different from Python, there

`/`

as integer division rounds towards negative infinity if https://www.geeksforgeeks.org/division-operator-in-python/ is correct and `//`

does the same even for floating point numbers where `/`

would do proper division.Vampire

11/19/2020, 10:06 AMSo I guess you actually need to use

`floor`

to get the same result as with Python `/`

if negative numbers are involved
and to get the same result as with Python `//`

.149 Views