Floor and Ceiling Function Calculator
The floor ⌊x⌋ is the largest integer not greater than x, and the ceiling ⌈x⌉ is the smallest integer not less than x. For x = −3.7, the floor is −4, the ceiling is −3, truncation gives −3 and the fractional part is 0.3.
Last updated · By S. Dilshan · Runs in your browser, nothing is uploaded
Step-by-Step Solution
What Are the Floor and Ceiling Functions?
The floor and ceiling functions turn any real number into a whole number in two different ways. The floor, ⌊x⌋, rounds down to the nearest integer. The ceiling, ⌈x⌉, rounds up. If x is already a whole number, both return x itself.
The subtle part is negative numbers. “Down” means toward negative infinity, so the floor of −3.7 is −4, not −3. This differs from simple truncation, which just discards the decimal part and moves toward zero.
Four Ways to Make an Integer
| x | ⌊x⌋ floor | ⌈x⌉ ceiling | Truncate | Round |
|---|---|---|---|---|
| 3.7 | 3 | 4 | 3 | 4 |
| 3.2 | 3 | 4 | 3 | 3 |
| 5 | 5 | 5 | 5 | 5 |
| −3.7 | −4 | −3 | −3 | −4 |
| −0.5 | −1 | 0 | 0 | −1 |
Floor and Ceiling Definitions and Identities
- The fractional part of a number is always between 0 (inclusive) and 1 (exclusive), even for negatives. For −3.7 it is −3.7 − (−4) = 0.3.
- The identity ⌈x⌉ = −⌊−x⌋ shows that the two functions are mirror images.
- Rounding to the nearest integer can be written ⌊x + 0.5⌋ for positive x.
For other rounding rules, see the rounding calculator.
Range Definitions
⌊x⌋ = n exactly when n ≤ x < n + 1, and ⌈x⌉ = n exactly when n − 1 < x ≤ n. These inequalities are the formal definitions and are handy for proofs.
In Programming
Python’s // operator and math.floor floor toward negative infinity, but integer division in C and Java truncates toward zero, so −7 ÷ 2 gives −3 there but −4 with floor division. Knowing which one your language uses prevents off-by-one bugs with negative values.
Billing “Per Hour or Part”
A car park charges $3 for each hour or part of an hour. A stay of 2 hours 10 minutes is 2.1667 hours, so the charge is 3 × ⌈2.1667⌉ = 3 × 3 = $9.
How Is It Calculated? Worked Examples
x = −3.7
- Floor: the greatest integer not above −3.7 is −4.
- Ceiling: the least integer not below −3.7 is −3.
- Truncate: drop the decimals toward zero: −3.
- Round half away from zero: −4.
- Fractional part: −3.7 − (−4) = 0.3.
x = 3.7
Floor 3, ceiling 4, truncation 3, rounding 4, fractional part 0.7.
Practical Questions
| Question | Calculation | Answer |
|---|---|---|
| How many tables for 47 students, 6 per table? | ⌈47 ÷ 6⌉ = ⌈7.83⌉ | 8 |
| How many full boxes from 47 items, 6 per box? | ⌊47 ÷ 6⌋ = ⌊7.83⌋ | 7 |
| A job takes 2.1 days. How many whole days to book? | ⌈2.1⌉ | 3 |
| Age in whole years at 25.9 years | ⌊25.9⌋ | 25 |
Pages and Remainders
Printing 1,000 items at 24 per page needs ⌈1,000 ÷ 24⌉ = ⌈41.67⌉ = 42 pages. The last page holds only 1,000 − 41 × 24 = 16 items.
Useful Identities
- Number of digits: a positive integer n has ⌊log₁₀ n⌋ + 1 digits. For 12,345: ⌊4.09⌋ + 1 = 5.
- Rounding: round(x) = ⌊x + 0.5⌋, so 3.5 becomes ⌊4.0⌋ = 4.
- Remainder: a mod n = a − n × ⌊a ÷ n⌋. For 17 mod 5: 17 − 5 × 3 = 2. For −7 mod 3: −7 − 3 × ⌊−2.33⌋ = −7 + 9 = 2.
How to Use This Floor and Ceiling Calculator
- Enter any real number, positive or negative.
- Read the floor, ceiling, truncation, rounding and the fractional part.
- Compare the results side by side, especially for negative inputs.
Where Floor and Ceiling Are Used
- Packing and planning: ceiling gives the number of boxes, vehicles or pages needed. See the long division calculator for the related quotient and remainder.
- Programming: floor division, array indexing and hash functions.
- Time and age calculations: whole years, days or hours.
- Number theory and algorithms: digit counts, binary search and the number of trailing zeros in a factorial.
- Finance: rounding charges up to the next whole billing unit.
What Are the Most Common Mistakes With the Floor and Ceiling Function Calculator?
- Treating floor as truncation for negatives. ⌊−3.7⌋ = −4, but truncating gives −3.
- Using the wrong function for “enough”. If you need enough boxes, use the ceiling, not the floor or round.
- Forgetting that integers are unchanged. ⌊5⌋ = ⌈5⌉ = 5.
- Mixing the sign of the fractional part. The fractional part x − ⌊x⌋ is never negative.
- Floating-point effects. In code, a value like 2.9999999999999996 can floor to 2 although you expect 3.
- Confusing the notation. ⌊ ⌋ is floor and ⌈ ⌉ is ceiling. Plain brackets [x] are sometimes used for floor in older texts.
Where Can You Verify These Formulas?
The definitions and formulas on this page follow standard references. Check them against these sources:
Built and maintained by S. Dilshan. Found a mistake? Email [email protected] with the page address.
Frequently Asked Questions
What is the floor of a negative number?
The floor moves toward negative infinity. ⌊−3.7⌋ = −4 and ⌊−0.5⌋ = −1.
What is the difference between floor and truncation?
They agree for positive numbers. For negatives, truncation moves toward zero (−3.7 becomes −3), while floor moves down (−3.7 becomes −4).
What is the ceiling function used for?
It gives the smallest whole number that is at least x. It is used whenever you need “enough”, such as the number of boxes, pages or vehicles.
What is the fractional part of a number?
It is x − ⌊x⌋, always between 0 and 1. For 3.7 it is 0.7 and for −3.7 it is 0.3.
Are floor and ceiling the same for integers?
Yes. For an integer n, ⌊n⌋ = ⌈n⌉ = n.
How is floor division related to the floor function?
Floor division a // b is ⌊a ÷ b⌋. In many programming languages it rounds toward negative infinity.