FLOOR

Rounds the returned value down to the next whole number. For example, each of these functions evaluates to 5:

floor(5.01)
floor(5.5)
floor(5.99) 

Behavior Type

Immutable

Syntax

FLOOR ( expression )

Parameters

expression 

Is an expression of type INTEGER or DOUBLE PRECISION.

Notes

FLOOR is the opposite of CEILING, which rounds the returned value up:

=> SELECT FLOOR(48.01) AS floor, CEIL(48.01) AS ceiling;
 floor | ceiling
-------+---------
    48 |      49
(1 row)

Examples

=> SELECT FLOOR((TIMESTAMP '2005-01-17 10:00' - TIMESTAMP '2005-01-01') / INTERVAL '7');
 FLOOR
-------
     2
(1 row)
=> SELECT FLOOR(-42.8);
 FLOOR 
-------
   -43
(1 row)
=> SELECT FLOOR(42.8);
 FLOOR 
-------
    42
(1 row)

Although the following example looks like an INTEGER, the number on the left is 2^49 as an INTEGER, but the number on the right is a FLOAT:

=> SELECT 1<<49, FLOOR(1 << 49);
    ?column?     |      floor      
-----------------+-----------------
 562949953421312 | 562949953421312
(1 row)

Compare the above example to:

=> SELECT 1<<50, FLOOR(1 << 50); 
     ?column?     |        floor         
------------------+----------------------
 1125899906842624 | 1.12589990684262e+15
(1 row)