Integer Floor Division

๐Ÿท๏ธ Numbers and Mathematical Operations / Arithmetic Operators

๐Ÿง  Context Introduction

When working with numbers in Python, you will often need to divide values and get a whole number result instead of a decimal. This is where integer floor division comes in. It performs division but always rounds the result down to the nearest whole number. This is especially useful when you need to distribute items evenly, calculate indices, or work with counts that cannot be fractional.


โš™๏ธ What Is Integer Floor Division?

Integer floor division uses the double forward slash operator: //

It divides two numbers and returns the largest whole number that is less than or equal to the result. Unlike regular division (which uses a single forward slash / and returns a float), floor division always gives you an integer result.

  • The operator is written as a // b
  • It works with both positive and negative numbers
  • The result is always an integer (or a whole number)

๐Ÿ“Š How It Works with Positive Numbers

With positive numbers, floor division behaves exactly like regular division but without the decimal part. You simply get the whole number portion.

  • 10 // 3 gives you 3 (because 10 divided by 3 is 3.33, and the floor is 3)
  • 20 // 4 gives you 5 (because 20 divided by 4 is exactly 5)
  • 7 // 2 gives you 3 (because 7 divided by 2 is 3.5, and the floor is 3)
  • 15 // 6 gives you 2 (because 15 divided by 6 is 2.5, and the floor is 2)

๐Ÿ•ต๏ธ How It Works with Negative Numbers

This is where floor division can be surprising. Remember: floor division always rounds down to the nearest whole number. On a number line, "down" means moving to the left.

  • -10 // 3 gives you -4 (because -10 divided by 3 is -3.33, and the floor is -4, which is less than -3.33)
  • -7 // 2 gives you -4 (because -7 divided by 2 is -3.5, and the floor is -4)
  • -20 // 4 gives you -5 (because -20 divided by 4 is exactly -5)
  • 10 // -3 gives you -4 (because 10 divided by -3 is -3.33, and the floor is -4)

๐Ÿ› ๏ธ Comparison: Regular Division vs. Floor Division

Operation Regular Division (/) Floor Division (//)
10 / 3 3.333... (float) 3 (integer)
-10 / 3 -3.333... (float) -4 (integer)
20 / 4 5.0 (float) 5 (integer)
-7 / 2 -3.5 (float) -4 (integer)
15 / 6 2.5 (float) 2 (integer)

๐Ÿงช Practical Use Cases

Floor division is commonly used in scenarios where you need to work with whole numbers only.

  • Distributing items evenly: If you have 23 items and 5 boxes, 23 // 5 tells you each box gets 4 items
  • Calculating page numbers: If you have 100 records and show 10 per page, 100 // 10 gives you 10 pages
  • Finding the middle index: For a list of 9 items, 9 // 2 gives you index 4 as the middle point
  • Converting units: If you have 150 minutes, 150 // 60 tells you there are 2 full hours

โš ๏ธ Important Notes to Remember

  • Floor division always rounds down, not toward zero
  • For positive numbers, floor division and truncation (removing the decimal) give the same result
  • For negative numbers, floor division gives a result that is more negative than truncation
  • The result type is int when both operands are integers, and float when one operand is a float
  • If you need to round toward zero instead of down, use the int() function with regular division

โœ… Quick Summary

  • Use // for integer floor division
  • It returns the largest whole number less than or equal to the division result
  • With positive numbers, it simply removes the decimal part
  • With negative numbers, it rounds further down (more negative)
  • It is essential for counting, indexing, and distribution problems

Integer floor division is a powerful tool that helps you work with whole numbers cleanly and predictably. Practice with both positive and negative values to build a strong intuition for how it behaves in every situation.


Integer floor division (//) divides two numbers and returns the largest whole integer that is less than or equal to the result, discarding any remainder.

โž— Example 1: Basic floor division of positive integers

This example shows how floor division works with two positive whole numbers.

result = 10 // 3
print(result)

๐Ÿ“ค Output: 3


โž— Example 2: Floor division with a remainder present

This example demonstrates that floor division always rounds down to the nearest whole number, even when the remainder is large.

result = 20 // 6
print(result)

๐Ÿ“ค Output: 3


โž— Example 3: Floor division with negative numbers

This example shows how floor division behaves when one of the numbers is negative โ€” it rounds toward negative infinity, not toward zero.

result = -10 // 3
print(result)

๐Ÿ“ค Output: -4


โž— Example 4: Floor division with both numbers negative

This example demonstrates that when both numbers are negative, the result is still rounded down toward negative infinity.

result = -10 // -3
print(result)

๐Ÿ“ค Output: 3


โž— Example 5: Practical use โ€” calculating how many full boxes are needed

This example shows a real-world scenario where an engineer needs to know how many complete boxes can be filled with a given number of items.

total_items = 47
items_per_box = 10
full_boxes = total_items // items_per_box
print(full_boxes)

๐Ÿ“ค Output: 4


Comparison: Floor Division vs. Regular Division

Operation Expression Result Description
Regular Division 10 / 3 3.3333 Returns a float with the exact quotient
Floor Division 10 // 3 3 Returns an integer, rounded down
Regular Division (negative) -10 / 3 -3.3333 Returns a float with the exact quotient
Floor Division (negative) -10 // 3 -4 Returns an integer, rounded toward negative infinity

๐Ÿง  Context Introduction

When working with numbers in Python, you will often need to divide values and get a whole number result instead of a decimal. This is where integer floor division comes in. It performs division but always rounds the result down to the nearest whole number. This is especially useful when you need to distribute items evenly, calculate indices, or work with counts that cannot be fractional.


โš™๏ธ What Is Integer Floor Division?

Integer floor division uses the double forward slash operator: //

It divides two numbers and returns the largest whole number that is less than or equal to the result. Unlike regular division (which uses a single forward slash / and returns a float), floor division always gives you an integer result.

  • The operator is written as a // b
  • It works with both positive and negative numbers
  • The result is always an integer (or a whole number)

๐Ÿ“Š How It Works with Positive Numbers

With positive numbers, floor division behaves exactly like regular division but without the decimal part. You simply get the whole number portion.

  • 10 // 3 gives you 3 (because 10 divided by 3 is 3.33, and the floor is 3)
  • 20 // 4 gives you 5 (because 20 divided by 4 is exactly 5)
  • 7 // 2 gives you 3 (because 7 divided by 2 is 3.5, and the floor is 3)
  • 15 // 6 gives you 2 (because 15 divided by 6 is 2.5, and the floor is 2)

๐Ÿ•ต๏ธ How It Works with Negative Numbers

This is where floor division can be surprising. Remember: floor division always rounds down to the nearest whole number. On a number line, "down" means moving to the left.

  • -10 // 3 gives you -4 (because -10 divided by 3 is -3.33, and the floor is -4, which is less than -3.33)
  • -7 // 2 gives you -4 (because -7 divided by 2 is -3.5, and the floor is -4)
  • -20 // 4 gives you -5 (because -20 divided by 4 is exactly -5)
  • 10 // -3 gives you -4 (because 10 divided by -3 is -3.33, and the floor is -4)

๐Ÿ› ๏ธ Comparison: Regular Division vs. Floor Division

Operation Regular Division (/) Floor Division (//)
10 / 3 3.333... (float) 3 (integer)
-10 / 3 -3.333... (float) -4 (integer)
20 / 4 5.0 (float) 5 (integer)
-7 / 2 -3.5 (float) -4 (integer)
15 / 6 2.5 (float) 2 (integer)

๐Ÿงช Practical Use Cases

Floor division is commonly used in scenarios where you need to work with whole numbers only.

  • Distributing items evenly: If you have 23 items and 5 boxes, 23 // 5 tells you each box gets 4 items
  • Calculating page numbers: If you have 100 records and show 10 per page, 100 // 10 gives you 10 pages
  • Finding the middle index: For a list of 9 items, 9 // 2 gives you index 4 as the middle point
  • Converting units: If you have 150 minutes, 150 // 60 tells you there are 2 full hours

โš ๏ธ Important Notes to Remember

  • Floor division always rounds down, not toward zero
  • For positive numbers, floor division and truncation (removing the decimal) give the same result
  • For negative numbers, floor division gives a result that is more negative than truncation
  • The result type is int when both operands are integers, and float when one operand is a float
  • If you need to round toward zero instead of down, use the int() function with regular division

โœ… Quick Summary

  • Use // for integer floor division
  • It returns the largest whole number less than or equal to the division result
  • With positive numbers, it simply removes the decimal part
  • With negative numbers, it rounds further down (more negative)
  • It is essential for counting, indexing, and distribution problems

Integer floor division is a powerful tool that helps you work with whole numbers cleanly and predictably. Practice with both positive and negative values to build a strong intuition for how it behaves in every situation.

Interactive Views

You are currently in ๐Ÿ“š All-in-One mode. Use the tabs at the top to switch to ๐Ÿ“– Theory Only or ๐Ÿ’ป Code Only views.

Integer floor division (//) divides two numbers and returns the largest whole integer that is less than or equal to the result, discarding any remainder.

โž— Example 1: Basic floor division of positive integers

This example shows how floor division works with two positive whole numbers.

result = 10 // 3
print(result)

๐Ÿ“ค Output: 3


โž— Example 2: Floor division with a remainder present

This example demonstrates that floor division always rounds down to the nearest whole number, even when the remainder is large.

result = 20 // 6
print(result)

๐Ÿ“ค Output: 3


โž— Example 3: Floor division with negative numbers

This example shows how floor division behaves when one of the numbers is negative โ€” it rounds toward negative infinity, not toward zero.

result = -10 // 3
print(result)

๐Ÿ“ค Output: -4


โž— Example 4: Floor division with both numbers negative

This example demonstrates that when both numbers are negative, the result is still rounded down toward negative infinity.

result = -10 // -3
print(result)

๐Ÿ“ค Output: 3


โž— Example 5: Practical use โ€” calculating how many full boxes are needed

This example shows a real-world scenario where an engineer needs to know how many complete boxes can be filled with a given number of items.

total_items = 47
items_per_box = 10
full_boxes = total_items // items_per_box
print(full_boxes)

๐Ÿ“ค Output: 4


Comparison: Floor Division vs. Regular Division

Operation Expression Result Description
Regular Division 10 / 3 3.3333 Returns a float with the exact quotient
Floor Division 10 // 3 3 Returns an integer, rounded down
Regular Division (negative) -10 / 3 -3.3333 Returns a float with the exact quotient
Floor Division (negative) -10 // 3 -4 Returns an integer, rounded toward negative infinity