About 51 results
Open links in new tab
  1. math - `/` vs `//` for division in Python - Stack Overflow

    In Python 3.x, 5 / 2 will return 2.5 and 5 // 2 will return 2. The former is floating point division, and the latter is floor division, sometimes also called integer division. In Python 2.2 or later in the 2.x line, …

  2. Integer division in Python 2 and Python 3 - Stack Overflow

    In Python 2.7, the / operator is integer division if inputs are integers. If you want float division (which is something I always prefer), just use this special import:

  3. python - Why does the division get rounded to an integer ... - Stack ...

    In Python 3, the “//” operator works as a floor division for integer and float arguments. However, the operator / returns a float value if one of the arguments is a float (this is similar to C++)

  4. division - What is the reason for having '//' in Python ... - Stack ...

    Oct 8, 2009 · In Python 3, they made the / operator do a floating-point division, and added the // operator to do integer division (i.e., quotient without remainder); whereas in Python 2, the / operator was …

  5. Python 3 integer division - Stack Overflow

    In Python 3 vs Python 2.6, I've noticed that I can divide two integers and get a float. How do you get the Python 2.6 behaviour back? Is there a different method to get int/int = int?

  6. math - Basic python arithmetic - division - Stack Overflow

    Python does integer division when both operands are integers, meaning that 1 / 2 is basically "how many times does 2 go into 1", which is of course 0 times. To do what you want, convert one operand to a …

  7. What is the result of % (modulo operator / percent sign) in Python?

    On Python 3 the calculation yields 6.75; this is because the / does a true division, not integer division like (by default) on Python 2. On Python 2 1 / 4 gives 0, as the result is rounded down.

  8. python - How can I force division to be floating point? Division keeps ...

    216 How can I force division to be floating point in Python? I have two integer values a and b, but I need their ratio in floating point. I know that a < b and I want to calculate a/b, so if I use integer division I'll …

  9. math - Integer division in Python - Stack Overflow

    Apr 19, 2022 · Python generally follows the Principle of Least Astonishment. It just always rounds down for integer division.

  10. python - How do you round UP a number? - Stack Overflow

    May 5, 2017 · The problem is that dividing two ints in python produces another int and that's truncated before the ceiling call. You have to make one value a float (or cast) to get a correct result.