What Is Floor Division

Floor division divides one number by another and rounds the quotient down to the greatest integer less than or equal to it. In Python, the operator is //, so 10 // 3 returns 3. The main details to understand are how negative numbers round, why a floor-division result can still be a float, and how integer division differs across programming languages.

How Floor Division Works

The word floor means the lower integer boundary of a number. Mathematically, floor division is written as ⌊a / b⌋, where a is the dividend and b is a nonzero divisor.

The operation has two parts:

  1. Divide the dividend by the divisor.
  2. Choose the greatest integer that does not exceed the quotient.

If the quotient is already an integer, floor division leaves its value unchanged. Otherwise, it moves down to the next lower integer, not necessarily toward zero.

For nonnegative counts and positive group sizes, floor division answers a practical question: How many complete groups fit?

That makes it useful for:

  • Counting full batches or completely filled containers.
  • Extracting whole units from a duration.
  • Mapping an index or coordinate into a fixed-width group.

Use floor division to count complete groups, not to count the containers needed to hold everything. If leftover items require another container, you need ceiling division, which rounds the quotient up.

How to Use Floor Division in Python

Choose the operator based on whether you need the ordinary quotient or a rounded-down quotient.

Goal Python Expression Behavior With Built-In Numbers
Keep the fractional quotient a / b Performs true division; integer operands produce a float
Round the quotient down a // b Performs floor division; the result’s type depends on the operands

Here is a complete example that counts full groups and leftover items.

Step 1: Set the Dividend and Divisor

  1. Store the number of items in items.
  2. Store the number of items per group in group_size.
items = 10
group_size = 3

For this counting task, use integers: a nonnegative item count and a positive group size.

A divisor of zero is invalid. Python raises ZeroDivisionError if you attempt either true division or floor division by zero.

Step 2: Calculate the Floor Quotient

  1. Place the dividend on the left of // and the divisor on the right.
  2. Store or print the result.
full_groups = items // group_size
print(full_groups)  # 3

This gives the number of groups you can fill completely. Floor division does not modify either input variable.

Step 3: Calculate Any Leftovers

  1. Use the modulo operator, %, to calculate the remainder.
  2. Keep that result if your program needs to handle items that do not fit into a complete group.
leftover_items = items % group_size
print(leftover_items)  # 1

You now have both parts of the calculation: the number of complete groups and the number of leftover items. This is more useful than the quotient alone when splitting work into batches or distributing items.

How Floor Division Handles Negative Numbers

The most common mistake is treating floor division as “remove everything after the decimal point.” That description works for positive quotients, but not for negative fractional quotients.

For example, negative ten divided by three is approximately negative 3.333. That value lies between negative four and negative three. Floor division chooses the lower integer: negative four.

print(-10 // 3)       # -4
print(int(-10 / 3))   # -3

These expressions use different rounding rules:

  • // rounds toward negative infinity.
  • int() converts a finite float to an integer by truncating toward zero.

The direction matters on a number line: moving down from a negative fractional value means moving farther below zero.

A Negative Divisor

A negative quotient can also result from dividing a positive number by a negative number. The rounding rule stays the same:

print(10 // -3)  # -4

It is the sign of the quotient, not just the dividend, that determines whether truncation and flooring can differ.

Two Negative Operands

When both operands are negative, their quotient is positive:

print(-17 // -5)  # 3

The ordinary quotient is 3.4, so its floor is 3. Floor division does not automatically make a result more negative just because its inputs contain minus signs.

Floor Division With Floats and Large Integers

Python’s built-in integers and floating-point numbers both support //, but their result types and precision characteristics differ.

Float Inputs Can Produce a Float Result

Floor division determines the rounded value, not necessarily the result’s data type.

For Python’s built-in int and float operands:

  • Two integer operands produce an int.
  • If either operand is a float, the result is a float.

Compare these operations:

import math
print(7.5 / 2)             # 3.75
print(7.5 // 2)            # 3.0
print(math.floor(7.5 / 2))  # 3

Here, 3.0 is a float with an integer-valued result. By contrast, math.floor() returns an integer.

Using // with floats does not remove floating-point approximation. Decimal fractions are not always represented exactly in binary, so calculations near an integer boundary can produce a surprising quotient. For exact item counts, indexes, or batch sizes, keep the operands as integers.

Large Integers Should Stay in Integer Arithmetic

For integer operands, prefer a // b over math.floor(a / b).

Although the expressions describe similar mathematics, they take different computational paths:

  • a // b calculates an integer floor quotient directly.
  • math.floor(a / b) first performs floating-point division, then floors that floating-point result.

The intermediate float can lose precision for large integers, and sufficiently large conversions can overflow. Applying math.floor() afterward cannot recover information already lost.

Python’s built-in integers support arbitrary precision, so direct integer floor division avoids that unnecessary conversion.

How to Check a Floor Division Result

For built-in integers, you can check floor division using the quotient and remainder together.

For a nonzero divisor, the results obey these rules:

  • The original dividend equals the divisor multiplied by the quotient, plus the remainder.
  • The remainder’s magnitude is smaller than the divisor’s magnitude.
  • A nonzero remainder has the same sign as the divisor.

Here is a runnable check using a negative dividend:

a = -10
b = 3
q, r = divmod(a, b)
assert a == b * q + r
assert abs(r) < abs(b)
assert r == 0 or (r > 0) == (b > 0)
print(q, r)  # -4 2

The positive remainder is intentional. Python pairs its remainder operation with floor division, so a negative dividend does not necessarily produce a negative remainder.

These checks are useful when porting code from a language whose integer division truncates toward zero. The quotient and remainder can both change even though the dividend and divisor stay the same.

Before using floor division in indexing or batching code, add tests for exact multiples, leftover items, and mixed-sign operands.

Frequently Asked Questions

What Is the Floor Division of 5 and 2?

The floor division of 5 by 2 is 2, written as 5 // 2 in Python. Ordinary division gives 2.5, and the greatest integer less than or equal to that value is 2.

What Is 7 Floor Division 2?

The result of 7 // 2 is 3. Dividing seven by two gives 3.5, which floor division rounds down to 3.

What Is Floor Division in Java?

In Java, Math.floorDiv(a, b) performs floor division for integer arguments. Unlike integer /, it rounds a negative fractional quotient toward negative infinity rather than toward zero.

System.out.println(Math.floorDiv(-10, 3)); // -4
System.out.println(-10 / 3);               // -3

What Is Floor Division in C++?

Floor division rounds the quotient toward negative infinity, which differs from truncation for negative fractional quotients. To obtain the floor quotient, subtract one from the truncated quotient when the division has a nonzero remainder and the operands have opposite signs.

#include <iostream>
int main() {
    const int a = -10;
    const int b = 3;
    int quotient = a / b;
    const int remainder = a % b;
    if (remainder != 0 && ((a < 0) != (b < 0))) {
        --quotient;
    }
    std::cout << quotient << '\n'; // -4
}

For variable inputs, check for a zero divisor and guard against dividing the minimum signed integer by -1 before calculating either the quotient or remainder, because that quotient is outside the type’s representable range.

What Is the Floor Division Operator?

Floor division returns the largest integer less than or equal to the quotient. In Python, it uses the double forward slash operator (//); for example, 10 // 3 evaluates to 3.