Floor Function
floor(x) is the greatest integer less than or equal to x. It rounds down toward negative infinity. Compare with ceiling, round, and fractional part.
Why This Mathematical Concept Matters
Why: The floor function is fundamental in integer division, array indexing, and modular arithmetic.
How: For positive x, floor truncates the decimal. For negative x, floor rounds toward −∞ (e.g., floor(−2.3) = −3).
- ●Integer division: a div b = floor(a/b) in many languages.
- ●floor(−2.3) = −3, not −2. Floor always rounds toward −∞.
- ●Fractional part {x} = x − floor(x) is used in hashing.
📐 Examples — Click to Load
Enter Number
Floor vs Ceiling vs Round
Integer vs Fractional
📐 Step-by-Step Breakdown
⚠️For educational and informational purposes only. Verify with a qualified professional.
🧮 Fascinating Math Facts
floor(3.7) = 3 and ceil(3.7) = 4. For integers, floor(n) = ceil(n) = n.
— Basics
Used in integer division: a div b = floor(a/b) in many programming languages.
— Programming
📋 Key Takeaways
- • floor(x) = greatest integer ≤ x. Rounds down toward negative infinity
- • For positive x: floor gives the integer part; for negative: floor is less than x
- • ceil(x) = least integer ≥ x. floor(-x) = -ceil(x)
- • Fractional part: {x} = x - floor(x), always in [0, 1) for positive x
💡 Did You Know?
📖 How It Works
The floor function maps x to the greatest integer less than or equal to x. For positive numbers, it truncates the decimal. For negative numbers, it rounds toward negative infinity (e.g., floor(-2.3) = -3).
📝 Worked Example: floor(-2.3)
Step 1: -2.3 lies between -3 and -2
Step 2: Greatest integer ≤ -2.3 is -3
Result: ⌊-2.3⌋ = -3
⚠️ Common Mistakes to Avoid
- floor(-2.3) = -2: Wrong. floor(-2.3) = -3. Floor rounds toward -∞.
- Confusing with trunc: trunc(-2.3) = -2; floor(-2.3) = -3.
- Fractional part for negatives: {x} = x - floor(x) can exceed 1 for negative x.
🎯 Expert Tips
💡 Negative numbers
floor(-2.3) = -3, not -2. Floor always rounds toward -∞.
💡 Integer division
In Python, a // b = floor(a/b). JavaScript: Math.floor(a/b).
❓ FAQ
What is the floor function?
floor(x) is the greatest integer less than or equal to x. It rounds down toward negative infinity.
How does floor differ from trunc?
For positive x they match. For negative: floor(-2.3) = -3, trunc(-2.3) = -2.
What is the fractional part?
{x} = x - floor(x). For 3.7, fractional part is 0.7.
When is floor used in programming?
Integer division (a // b), array indexing, pagination, and hashing.
What is the relationship between floor and ceiling?
floor(-x) = -ceil(x). For any real x: floor(x) ≤ x ≤ ceil(x).
⚠️ Disclaimer: For educational use. Uses JavaScript Math.floor which has floating-point precision limits for very large numbers.