SQL CEIL Vs FLOOR Function
In SQL , the fundamental distinction between CEIL
and FLOOR
is that CEIL assists in obtaining the lowest integer value that is more than or equal to a number.
whereas FLOOR assists in obtaining the greatest integer value that is less than or equal to number.
SQL CEIL Function
The CEIL() function is used to find the smallest integer value greater than or equal to a given number.
Example 1: When there is a poisitive number in the argument.
--Sqlserver,Mysql,Ms accessSELECT CEILING(21.53);
Output: The output of positive number argument is
Example 2: When there is a negative number in the argument.
SELECT CEILING(-21.53);
Output: The output of negative argument is
SQL FLOOR FUNCTION
The FLOOR () function is useful for finding the greatest integer value that is less than or equal to a given number.
The second input D and the number itself (digit after D decimal places >=5 or not) determine whether the ROUND()
function rounds the number up or down.
The FLOOR() method rounds the number to the nearest tenth value.
Example 1: When the argument holds a positive number.
SELECT FLOOR(21.53);
Output: The result of postive floor number is
Example 2 : When the argument holds a negative number.
SELECT FLOOR(-21.53);
Output: The result of negative floor number will be
SQL Difference Between CEIL And FLOOR Function
There is 1 main contrast between ceil & floor function discussed in below table:-
CEIL | FLOOR |
---|---|
CEIL() is a function that lets you find the lowest integer value that is greater than or equal to a given number. | FLOOR() can be used to get the largest integer value that is less than or equal to a given number. |