Which one of these is float division?

/ → Floating point division

// → Floor division

Let’s see some examples in both Python 2.7 and in Python 3.5.

Python 2.7.10 vs. Python 3.5

print (2/3)  ----> 0                   Python 2.7
print (2/3)  ----> 0.6666666666666666  Python 3.5

Python 2.7.10 vs. Python 3.5

print (4/2)  ----> 2         Python 2.7
print (4/2)  ----> 2.0       Python 3.5

Now if you want to have (in Python 2.7) the same output as in Python 3.5, you can do the following:

Python 2.7.10

from __future__ import division
print (2/3)  ----> 0.6666666666666666   # Python 2.7
print (4/2)  ----> 2.0                  # Python 2.7

Whereas there isn't any difference between floor division in both Python 2.7 and in Python 3.5.

138.93//3 ---> 46.0        # Python 2.7
138.93//3 ---> 46.0        # Python 3.5
4//3      ---> 1           # Python 2.7
4//3      ---> 1           # Python 3.5

The

101 / 4 = 25 with remainder 1

Code language: plaintext (plaintext)
8 is called the floor division operator or div. And the

101 / 4 = 25 with remainder 1

Code language: plaintext (plaintext)
9 is called the modulo operator or mod.

This tutorial focuses on the floor division operator. You’ll learn about the modulo operator in the following tutorial.

Both floor division and modulo operators satisfy the following equation:

101 = 4 * (101 // 4) + (101 % 4) 101 = 4 * 25 + 1

Code language: plaintext (plaintext)

Generally, if

101 / 4 = 25 with remainder 1

Code language: plaintext (plaintext)
6 is the numerator and

101 / 4 = 25 with remainder 1

Code language: plaintext (plaintext)
7 is the denominator, then the floor division and modulo operators always satisfy the following equation:

N = D * ( N // D) + (N % D)

Code language: plaintext (plaintext)

The floor division in Python

To understand the floor division, you first need to understand the floor of a real number.

The floor of a real number is the largest integer less than or equal to the number. In other words:

floor(r) = n, n is an integr and n <= r

Code language: plaintext (plaintext)

For example, the floor of 3.4 is 3 because 3 is the largest integer less than or equal to 3.4. The floor of 3.9 is also 3. And the floor of 3 is 3 obviously:

floor(3.4) = 4 floor(3.9) = 3 floor(3) = 3

Code language: plaintext (plaintext)

For the positive numbers, it would be easy to understand the definition. However, you should pay attention when it comes to negative numbers.

For example, the floor of

101 = 4 * 25 + 1

Code language: plaintext (plaintext)
4 returns

101 = 4 * 25 + 1

Code language: plaintext (plaintext)
5, not

101 = 4 * 25 + 1

Code language: plaintext (plaintext)
6 based on the floor definition. Similarly, the floor of

101 = 4 * 25 + 1

Code language: plaintext (plaintext)
7 also returns

101 = 4 * 25 + 1

Code language: plaintext (plaintext)
5 .

floor(-3.4) = -4 floor(-3.9) = -4 floor(-3) = -3

Code language: plaintext (plaintext)

The floor division can be defined as:

n // d = floor(n/d)

Code language: plaintext (plaintext)

Notice that the floor division of a number is not always the same as truncation. The floor division is the same as truncation only when the numbers are positive.

Python floor division operator examples

The following example uses the floor division operators with positive and negative integers:

101 / 4 = 25 with remainder 1

Code language: plaintext (plaintext)
0

Output:

101 / 4 = 25 with remainder 1

Code language: plaintext (plaintext)
1

The following table illustrates the floor division of two integers

101 = 4 * 25 + 1

Code language: plaintext (plaintext)
9 and

101 // 4 = 25 101 % 4 = 1

Code language: plaintext (plaintext)
0:

aba // b1033-10-3310-3-4-103-3

Python math.floor() function

The

101 // 4 = 25 101 % 4 = 1

Code language: plaintext (plaintext)
1 function of the

101 // 4 = 25 101 % 4 = 1

Code language: plaintext (plaintext)
2 module returns the floor division of two integers. For example:

101 / 4 = 25 with remainder 1

Code language: plaintext (plaintext)
2

Output:

101 / 4 = 25 with remainder 1

Code language: plaintext (plaintext)
3

As you can see clearly from the output, the

101 // 4 = 25 101 % 4 = 1

Code language: plaintext (plaintext)
1 function returns the same result as the floor division operator (

101 / 4 = 25 with remainder 1

Code language: plaintext (plaintext)
8). It’s also true for the negative numbers:

What is a floating division?

The float division operation / is used when you want a more precise division result, as it does not round off the value to whole numbers. It must be noted that for recurring decimal values, there is a limit to how many digits a float variable can store, so it is not always possible to store the exact value.

Which one of these is floor division *?

2. Which one of these is floor division? Explanation: When both of the operands are integer then python chops out the fraction part and gives you the round off value, to get the accurate answer use floor division. This is floor division.

What is floor division examples?

1. Example of / and // with a positive integer. In the above code, we can see that when we divide 15 by 4, the result will be 3.75. When we use Floor division for 15 and 4, we see that the output will be 3 that is, the 3.75 is rounded off to the nearest integer which is 3.

What is meant by floor division?

Floor division is a normal division operation except that it returns the largest possible integer. This integer is either less than or equal to the normal division result. Floor function is mathematically denoted by this ⌊ ⌋ symbol.