0

Pretty new to python, facing a problem that requires basically the opposite of the remainder "%" function. For example, if I wanted to divide 81.5 by 20, my output would be 4. My best attempt is as follows:

amount = 81.504
round(amount, 2)

num20s = amount / 20
int(num20s)

I've tried several different combinations of the above code, but nothing has worked so far. This is the closest I've gotten to what I want, but it won't work in edge cases, and for some reason still represents the number with a ".0" at the end, so that last line must not be doing anything.

  • 1
    sounds like what you want is floor division `//` – SuperStew Feb 06 '20 at 22:30
  • Yes that's exactly what I needed, thank you! Everything is still being represented as float numbers though, I'll have to continue working on that. – Nicholas Womack Feb 06 '20 at 22:43
  • Does this answer your question? [Python integer division yields float](https://stackoverflow.com/questions/1282945/python-integer-division-yields-float) – AMC Feb 06 '20 at 23:22

1 Answers1

1

Integer division operator in python is "//".

>>> amount = 81.504
>>> amount // 20
Out[3]: 4.0
>>> int(amount // 20)
Out[4]: 4
benji
  • 376
  • 1
  • 7