Floor Division Calculator
Free Floor division Calculator for arithmetic. Enter values to get step-by-step solutions with formulas and graphs. Get results you can export or share.
Reviewed for accuracy by Manoj Kumar, Mathematics Educator
Floor Division Calculator
Calculator
Adjust values & calculateEnter your values below. Every result is computed in your browser โ no data is sent to any server.
Formula: floor(a / b) = largest integer less than or equal to a/b
Worked example โ 17 // 5 = 3 remainder 2
Formula
floor(a / b) = largest integer less than or equal to a/b
Where a is the dividend, b is the divisor, and floor rounds the exact quotient toward negative infinity. The floor remainder is computed as a - b * floor(a/b), which always has the same sign as b.
Worked Examples
Example 1: Positive Floor Division
Problem:Compute 17 floor-divided by 5 and find the remainder.
Solution:Exact division: 17 / 5 = 3.4 Floor division: floor(3.4) = 3 Remainder: 17 - 5 * 3 = 17 - 15 = 2 Verification: 5 * 3 + 2 = 17 In Python: 17 // 5 = 3, 17 % 5 = 2
Result:17 // 5 = 3 remainder 2
Example 2: Negative Floor Division vs Truncation
Problem:Compare floor division and truncation for -17 divided by 5.
Solution:Exact division: -17 / 5 = -3.4 Floor division: floor(-3.4) = -4 Floor remainder: -17 - 5 * (-4) = -17 + 20 = 3 Verify: 5 * (-4) + 3 = -20 + 3 = -17 Truncation: trunc(-3.4) = -3 Trunc remainder: -17 - 5 * (-3) = -17 + 15 = -2 Verify: 5 * (-3) + (-2) = -15 - 2 = -17
Result:Floor: -17 // 5 = -4 R 3 | Truncation: trunc(-17/5) = -3 R -2
Frequently Asked Questions
What is floor division and how is it different from regular division?
Floor division divides two numbers and then rounds the quotient DOWN to the nearest integer (toward negative infinity). Regular division gives the exact decimal result, while floor division always produces a whole number. For positive numbers, floor division is the same as integer division: 17 floor-divided by 5 = 3 (since 17/5 = 3.4, and floor(3.4) = 3). The key difference emerges with negative numbers: -17/5 = -3.4, and floor(-3.4) = -4 (not -3). This is distinct from truncation, which would give -3 by rounding toward zero. In Python, the // operator performs floor division, making it one of the most commonly used integer division operations in programming.
How does floor division differ from truncation division?
Floor division rounds toward negative infinity, while truncation rounds toward zero. For positive numbers, both produce identical results: floor(7/2) = trunc(7/2) = 3. The difference appears with negative results: floor(-7/2) = floor(-3.5) = -4, but trunc(-7/2) = trunc(-3.5) = -3. Truncation chops off the decimal part regardless of sign, while floor always rounds down. This distinction matters because the remainder changes too. With floor division: -7 = 2 * (-4) + 1 (remainder is positive). With truncation: -7 = 2 * (-3) + (-1) (remainder is negative). Python uses floor division for // and floor-based modulo for %, while C and Java use truncation for integer division and truncation-based modulo.
Why does Python use floor division instead of truncation?
Python uses floor division because it produces mathematically cleaner behavior for the modulo operator. With floor division, the remainder always has the same sign as the divisor, which means n % m always returns a value in the range [0, m) for positive m. This property is extremely useful for cyclic operations like clock arithmetic, array indexing, and hash tables. For example, (-1) % 12 = 11 in Python (which makes sense for clock arithmetic: one hour before 12 is 11), but (-1) % 12 = -1 in C (which is less intuitive). Guido van Rossum, Python's creator, explained this choice in a blog post, noting that the mathematical definition of modulo works better with floor division for most practical applications.
What is the modulo operator and how does it relate to floor division?
The modulo operator gives the remainder after division, but its exact behavior depends on which type of division is used. With floor division, the modulo is defined as a mod b = a - b * floor(a/b), and the result always has the same sign as the divisor b. With truncation division, modulo is a mod b = a - b * trunc(a/b), and the result has the same sign as the dividend a. For example, -7 mod 3: with floor-based modulo, -7 mod 3 = -7 - 3*floor(-7/3) = -7 - 3*(-3) = -7 + 9 = 2. With truncation-based modulo: -7 mod 3 = -7 - 3*trunc(-7/3) = -7 - 3*(-2) = -7 + 6 = -1. Both satisfy the identity a = b * quotient + remainder.
Which programming languages use floor division vs truncation?
Different programming languages make different choices for integer division. Python uses floor division with its // operator and floor-based modulo with %. Ruby and Dart also use floor division for their integer division operators. On the other hand, C, C++, Java, JavaScript, and C# use truncation for integer division and truncation-based modulo. This difference is a common source of bugs when porting code between languages, especially when negative numbers are involved. In JavaScript, there is no built-in floor division operator, so you must use Math.floor(a/b) explicitly. Some languages like Haskell provide both options with different function names: div/mod for floor-based and quot/rem for truncation-based.
How is floor division used in array indexing and data structures?
Floor division is essential for converting between different coordinate systems and for partitioning data. In a 2D grid stored as a 1D array, the row of element at index i in a grid with w columns is floor(i/w), and the column is i mod w. For hash tables, floor division helps distribute keys across buckets. In tile-based games, floor division converts pixel coordinates to tile coordinates: tile_x = floor(pixel_x / tile_width). Calendar calculations use floor division extensively: the day of the week, the week number of the year, and Julian-to-Gregorian conversions all rely on floor division. The consistency of floor division with positive remainders makes these calculations correct even at boundary cases.
What is the Euclidean division theorem?
The Euclidean division theorem states that for any integers a and b with b not equal to zero, there exist unique integers q (quotient) and r (remainder) such that a = b * q + r, where 0 is less than or equal to r and r is less than the absolute value of b. This is the mathematical foundation for floor division with positive divisors. The quotient q corresponds to floor(a/b) when b is positive. For example, dividing -13 by 5: -13 = 5 * (-3) + 2, where q = -3 and r = 2. The theorem guarantees that the remainder is always non-negative, which aligns with floor division behavior. This is fundamental in number theory, forming the basis for the Euclidean algorithm, modular arithmetic, and continued fractions.
How does floor division handle decimal inputs?
Floor division applies to any real numbers, not just integers. For decimal inputs, the process is the same: divide normally, then take the floor. For example, 7.5 floor-divided by 2.3: first compute 7.5 / 2.3 = 3.2608..., then floor gives 3. The remainder is 7.5 - 2.3 * 3 = 7.5 - 6.9 = 0.6. With negative decimals: -7.5 floor-divided by 2.3: -7.5 / 2.3 = -3.2608..., floor gives -4. The remainder is -7.5 - 2.3 * (-4) = -7.5 + 9.2 = 1.7. In Python, the // operator works with floats and returns a float: 7.5 // 2.3 = 3.0. Floating-point precision can sometimes cause unexpected results, so care is needed when working with decimal floor division.
What are practical applications of floor division in everyday math?
Floor division appears in many practical scenarios. Converting 157 minutes to hours: floor(157/60) = 2 hours with 157 - 60*2 = 37 minutes remaining. Distributing 23 cookies among 5 children: each gets floor(23/5) = 4 cookies with 3 left over. Converting cents to dollars and cents: $3.47 has floor(347/100) = 3 dollars and 47 cents. Pagination: with 97 items and 10 per page, you need ceil(97/10) = 10 pages, or equivalently floor((97-1)/10) + 1 = 10 pages. Time zone conversions, payroll calculations (overtime hours), packaging problems (how many boxes needed), and inventory management all use floor division regularly.
How does floor division work with negative numbers and why does the sign matter?
When both numbers have the same sign, floor division behaves intuitively: 17 // 5 = 3 and -17 // -5 = 3. When signs differ, the result is rounded toward negative infinity, which may seem counterintuitive at first. For -17 // 5: the exact quotient is -3.4, and floor(-3.4) = -4. For 17 // -5: the exact quotient is -3.4, and floor(-3.4) = -4. The sign matters because it determines the direction of rounding. With truncation, -17 divided by 5 gives -3, but with floor division it gives -4. The corresponding remainders are different too: floor remainder = -17 - 5*(-4) = 3 (positive), truncation remainder = -17 - 5*(-3) = -2 (negative). Understanding this behavior is critical for writing correct code involving negative indices.
References
Reviewed for accuracy by Manoj Kumar, Mathematics Educator ยท Editorial policy
Related Calculators
๐งฎPolynomial Division Calculator
Calculate polynomial division with inputs, formulas, and instant results.
๐งฎSynthetic Division Calculator
Calculate synthetic division with inputs, formulas, and instant results.
๐งฎDivision Calculator
Calculate division with inputs, formulas, and instant results.
๐งฎFloor Function Calculator
Calculate floor function with inputs, formulas, and instant results.
๐งฎBinary Division Calculator
Calculate binary division with inputs, formulas, and instant results.
๐งฎLong Division Calculator
Calculate long division with inputs, formulas, and instant results.
๐งฎAnnulus Area Calculator
Calculate annulus area with inputs, formulas, and instant results.
๐งฎArea Calculator
Calculate area with inputs, formulas, and instant results.