The floor and ceiling calculator above applies every common integer-part function to a number at the same time: floor, ceiling, truncation toward zero, round half up, round half away from zero and round half to even. It also snaps the value onto a grid of any spacing you choose. Seeing all of them together is the point, because for a positive number that is not a tie they mostly agree, and for a negative number or a half-integer they scatter in five different directions.
Arb Digital publishes this page because the disagreement causes real bugs. A pagination routine that uses truncation instead of ceiling loses the last page. A billing calculation that truncates instead of flooring quietly favours one side on refunds. A statistics report that uses a language's default rounding introduces a systematic bias its author never intended. Every one of those is a difference of one unit that only appears in the cases nobody tested.
What This Floor and Ceiling Calculator Does
It reports the five integer-mapping functions for two values side by side, so you can compare a positive and a negative case, or a tie and a non-tie, without running it twice. It also gives the fractional part, which is defined as x minus the floor of x and is therefore always in the range from zero up to but not including one — including for negatives, where it catches people out.
The multiple field extends the same operations to any grid spacing. Flooring to a multiple of 0.25 gives the largest quarter not exceeding your value; ceiling to a multiple of 100 rounds a figure up to the next hundred. This is the operation behind pricing tiers, time buckets and allocation blocks, and it is where floating point most often produces an answer one step out.
Note the boundary with our rounding calculator, which rounds to a chosen number of decimal places and is the tool you want for presentation. This page is about mapping a real number onto an integer or onto a grid, which is a different operation with different edge cases.
How to Use It
- Enter your value. The headline shows its floor, and the grid shows the other four functions applied to the same number.
- Enter a second value. Pick one that contrasts with the first — a positive against a negative, or a tie against a non-tie — and read the table across.
- Set the multiple. Leave it at 1 for ordinary integers, or set a grid spacing to snap onto quarters, fives, hundreds and so on.
- Compare the rows that disagree. Those are the cases where the choice of function changes your answer, and they are the cases worth writing a test for.
The Definitions and How They Are Calculated
The floor of x, written ⌊x⌋, is the greatest integer less than or equal to x. The ceiling, written ⌈x⌉, is the least integer greater than or equal to x. Both always move in a fixed direction on the number line: floor moves left, ceiling moves right, whatever the sign. Wolfram MathWorld's page on the floor function notes it is also called the greatest integer function, and records that the modern square-bracket notation was displaced in favour of the floor and ceiling brackets precisely because they make the pairing obvious.
Truncation discards the fractional part, which moves toward zero rather than in a fixed direction. It equals floor for positive numbers and ceiling for negative ones, which is why code that truncates behaves inconsistently across the sign change. Round half up is floor(x + 0.5) and moves ties toward positive infinity. Round half away from zero is the convention taught in schools and moves ties outward in both directions. Round half to even sends ties to whichever neighbour is even.
The fractional part is defined as x − ⌊x⌋. For 3.7 that is 0.7, as expected. For −3.7 it is −3.7 − (−4) = 0.3, not −0.7 and not 0.7. The fractional part is always non-negative under this definition, and code that computes it by taking the remainder instead will disagree for every negative input.
Negative Numbers Are Where Everything Diverges
For 3.7 the answers are: floor 3, ceiling 4, truncation 3, round half up 4, round half to even 4. Four of the five agree with the intuition that "3.7 becomes 4 or 3". For −3.7 they are: floor −4, ceiling −3, truncation −3, round half up −4, round half to even −4. Truncation has switched sides. It matched floor on the positive and matches ceiling on the negative.
This is the single most common source of off-by-one errors involving these functions, because most programming languages give you truncation by default when converting a float to an integer, and most developers test with positive numbers. A function that computes an index, a page count or a bucket number will pass every test and then be wrong by one the first time a negative arrives.
Integer division has the same split. Some languages define integer division as truncating toward zero, so −7 divided by 2 is −3; others define it as flooring, giving −4. The remainder operator inherits whichever convention the division uses, so the sign of a modulo result varies by language for negative operands. If you need a genuinely non-negative remainder, compute it explicitly rather than trusting the operator.
The Three Rounding Conventions and Their Biases
A tie is a value exactly halfway between two integers, and the three conventions resolve it differently. Round half up sends every tie toward positive infinity, so 2.5 becomes 3 and −2.5 becomes −2. This is what JavaScript's built-in rounding does, and it is asymmetric: it introduces an upward drift across a set of values containing ties.
Round half away from zero sends 2.5 to 3 and −2.5 to −3. It is symmetric about zero, which is why it is the school convention and why it appears in many financial specifications. It still has a drift, though: over a large set of positive values with ties, it pushes the total upward, because ties always go up and there is nothing pulling them down.
Round half to even — also called banker's rounding — sends 2.5 to 2 and 3.5 to 4, choosing the even neighbour each time. Because ties are then split roughly evenly between rounding up and rounding down, the bias cancels over many values. MathWorld's page on the nearest integer function records this as the standard rule, adding it "in order to avoid statistical biasing", and notes it is what the C language's rint and Wolfram Language's Round implement. It is also the default in the IEEE 754 floating point standard and in several statistical languages, which is why a sum of rounded values can differ between two tools that both look like they round correctly.
Snapping to a Grid, and the Floating Point Trap
Flooring to a multiple of m is m × ⌊x/m⌋, and the ceiling version replaces floor with ceiling. Simple in principle, and unreliable in binary floating point for exactly the values people use. The multiple 0.1 is not representable in binary, so 0.3/0.1 evaluates to 2.9999999999999996 rather than 3, and a naive floor turns 0.3 into 0.2.
This calculator guards against that by snapping the quotient to the nearest integer whenever it is within a small tolerance before applying the function. That is the standard fix, and it is worth knowing about because it is not what a one-line implementation does. If a grid calculation in your own code ever produces an answer one step low, the quotient landing a fraction below an integer is almost certainly why. Our decimal to fraction calculator shows which decimals have exact representations, and our fraction calculator lets you avoid the problem entirely by staying in exact arithmetic.
Where These Functions Show Up in Practice
Ceiling handles anything where a partial unit still consumes a whole one: pages needed for a list of items, containers needed for a shipment, minutes billed for a call. The formula is always ceiling(total/capacity), and using truncation or plain rounding there silently drops the final partial unit.
Floor handles anything where a partial unit yields nothing: how many complete items you can afford, how many full periods have elapsed, how many whole batches a supply can produce. Truncation handles the narrower case of taking the integer part of a magnitude regardless of direction, which is what you want for digit extraction and little else.
Rounding handles presentation and measurement, and there the convention should be stated rather than defaulted. Our significant figures calculator covers the digit-counting rules that go with it, our scientific calculator handles the surrounding arithmetic, and our number base converter is useful when the integer you land on then has to be expressed in another base.
A Worked Example You Can Check Yourself
Take x = −3.7. The integers either side are −4 and −3. Floor takes the one that is not above x, which is −4. Ceiling takes the one that is not below x, which is −3. Truncation drops the fractional part of the magnitude 3.7 to give 3, then restores the sign: −3. So truncation agrees with ceiling here and with floor for the positive equivalent. The fractional part is −3.7 − (−4) = 0.3.
Now take y = 2.5, an exact tie. Floor is 2 and ceiling is 3. Round half up gives floor(2.5 + 0.5) = floor(3) = 3. Round half away from zero also gives 3. Round half to even picks the even neighbour of 2 and 3, which is 2. So the same number becomes 3 under two conventions and 2 under the third, and if you were rounding a column of such values the totals would differ.
Finally the grid. With a multiple of 0.25, flooring −3.7 means computing −3.7/0.25 = −14.8, flooring that to −15, and multiplying back: −3.75. The ceiling version gives −14 × 0.25 = −3.5. Both sit one quarter apart and straddle the original value, which is exactly what floor and ceiling on a grid should do.
Arb Digital's team traces the numbers back to the function that produced them, which is usually a rounding convention nobody chose deliberately.
Browse All Free Tools Talk To Our TeamCommon Mistakes to Avoid
- Using truncation where you meant floor — they agree for positives and disagree for every negative, so the bug only appears once real data arrives.
- Assuming the language's round is symmetric — several round ties toward positive infinity, which sends 2.5 to 3 but −2.5 to −2.
- Computing the fractional part with a remainder operator — the mathematical definition x minus floor of x is never negative, and the remainder version is negative for negative inputs.
- Flooring onto a grid without a tolerance — binary floating point makes quotients land a hair below the integer they should be, dropping a whole step.
- Rounding twice — rounding to two decimals and then to the nearest integer can move a value further than rounding once, because the intermediate result can be pushed across a tie.
Related Free Tools From Arb Digital
Round to a number of decimal places with the rounding calculator, get the digit rules right with the significant figures calculator, run the surrounding arithmetic in the scientific calculator, check which decimals are exact with the decimal to fraction calculator, stay in exact arithmetic with the fraction calculator, or express the result elsewhere with the number base converter. The free online tools hub lists every maths tool we publish.
Frequently Asked Questions
They are identical for positive numbers and opposite for negative ones. Floor always moves toward negative infinity, while truncation always moves toward zero, so the floor of minus 3.7 is minus 4 but its truncation is minus 3.
The greatest integer that is not above it, which means moving further from zero. The floor of minus 2.1 is minus 3, not minus 2, because minus 3 is the largest integer that does not exceed minus 2.1.
They are using round half to even, also called banker's rounding, which sends ties to the nearest even integer. It is designed so that ties go up and down about equally often, which removes the systematic upward drift of always rounding ties away from zero.
Under the standard definition of x minus the floor of x it is always between zero and one. For minus 3.7 the floor is minus 4, so the fractional part is 0.3.
Divide by five, take the ceiling, then multiply by five again. The same pattern works for any grid spacing, and the tool above does it for whatever multiple you enter.
Because binary floating point cannot represent most decimal fractions exactly, so a quotient that should be a whole number lands microscopically below it. Snapping the quotient to the nearest integer within a small tolerance before flooring fixes it.
Yes. Floor, ceiling and truncation all return an integer unchanged, because it is already both the greatest integer not above it and the least integer not below it.
This page explains a mathematical operation for educational purposes only. Rounding rules used in accounting, tax and regulated billing are set by the relevant standard or authority, and the convention it specifies takes precedence over any default shown here.