Videos
Give examples of floor and ceiling functions.
What is the difference between ceiling function and floor function?
How to calculate the ceiling value?
Simply put it's two ways of thinking of rounding off a number. Ceiling rounds up to nearest integer. Floor rounds down to nearest integer. If the number is an integer, nothing happens.
It's easy to think about floor and ceil from the perspective of the number line.
Let's say you have some decimal number, (I'm going to be using this number as an example throughout my answer)

So, as you can see, the functions just return the nearest integer values.
floor returns the nearest lowest integer and ceil returns the nearest highest integer.
All real numbers are made of a characteristic (an integer part) and mantissa (a fractional part)
When floor a number, you can think of it as replacing the Mantissa with
and ceil can be thought of as replacing the mantissa with .
That's not a very popular way of thinking about it but it was the way I thought about it when I first started using it in programming.
Remember, the number remains the same when it is an integer.
ie, floor()
ceil(
)
Let's now look at the proper definitions along with the graphs for them.
Floor Function: Returns the greatest integer that is less than or equal to

Ceiling Function: Returns the least integer that is greater than or equal to

Don't let the infinite staircase scare you. It's much more simpler than it seems. Those "line-segments" that you see are actually called piecewise-step functions.
Simply, the black dot represents 'including this number' and the white represents 'excluding this number'. Meaning that each segment actually is from x to all numbers less than x+1.
Let's look at 2.31 and how it would look on both the graphs at once.
You can see that the line This is apples vs. oranges. In most languages/APIs, min/max take two (or more) inputs, and return the smallest/biggest. floor/ceil take one argument, and round it down or up to the nearest integer.
To my knowledge max and min are used on a collection, say an array of numbers. Floor and ceiling are used for single numbers. For example:
min(1, 2, 3, 4) => 1
max(1, 2, 3, 4) => 4
floor(3.5) => 3
ceiling(3.5) => 4
John wrote:
I am looking for a single function that will do EITHER a ROUNDUP or ROUNDOWN based on the value. (i.e. on a scale from 1-10, if the value is 1-4, I want to round the value down; if value is 5-10, I want to round the value up). Is there such a function that will do this in a single calculation?
That's the very definition of ROUND. But your example is ambiguous insofar as it is unclear what digit you are talking about rounding.
If you want 1.4 in A1 to round to 1 and 1.5 to round to 2, use ROUND(A1,0).
If you want 14 to round to 10 and 15 to round to 20, use ROUND(A1,-1).
See the ROUND help page for more details.
PS: For future reference, when you have a question, start a new discussion instead of piggybacking an old discussion, much less a discusion marked "answer".
First, usually no two questions are every identical in all details. So your specifics might require a completely different direction.
Second, some helpful people might never see your new "response" because they do not look at discussions marked "answer".
Finally, since you are not the original poster, you have no way to mark responses to your question as "answer".
Thank you joeu2004 for the help with this function and for the blog etiquette tips. Sorry, I'm a newbie learning. Have a blessed day.
When I truncate a number what my brain actually does is ignoring the fractional part of said number. But its not doing any real math.
I understand I can express a truncate function with conditional floor and cealing functions... but thats is not what I need.
I need someone to teach me how to arrive from a number to its integer using only mathematical operations and not logical functions.
I need to know...
Plz help me someone...
To add to Hyperboreus' answer, this is strictly speaking not an ABAP question, as the ceiling and floor functions are generic mathematical functions included in other languages too.
You can try it for yourself with the following ABAP code to get a hands-on understanding:
data: v type p decimals 1.
data: c type i.
data: f type i.
v = '8.2'.
c = ceil( v ).
f = floor( v ).
write: c, f.
Unfortunatly I do not know a thing about abap, but ceil and floot are generally defined as follows:
The floor of a float value is the next lowest integer.
The ceiling of a float value is the next highest integer.
Exempli gratia:
ceil (4.1) = 5
floor (4.1) = 4



