PostgreSQL FLOOR() Function
The PostgreSQL FLOOR() function returns the next lowest integer value by rounding down the specified number, if necessary. In other words, it rounds the fraction DOWN of the given number.
Syntax
FLOOR(x)
Parameters
x |
Required. Specify a number. |
Return Value
Returns the next lowest integer value by rounding DOWN the specified number, if necessary.
Example 1:
The example below shows the usage of FLOOR() function.
SELECT FLOOR(23); Result: 23 SELECT FLOOR(23.3); Result: 23 SELECT FLOOR(23.8); Result: 23 SELECT FLOOR(-23); Result: -23 SELECT FLOOR(-23.3); Result: -24 SELECT FLOOR(-23.8); Result: -24
Example 2:
Consider a database table called Sample with the following records:
Data | x |
---|---|
Data 1 | -10.75 |
Data 2 | -5.38 |
Data 3 | 0.98 |
Data 4 | 13.16 |
Data 5 | 48.13 |
The statement given below can be used to round the fraction DOWN for all records of column x.
SELECT *, FLOOR(x) AS FLOOR_Value FROM Sample;
This will produce the result as shown below:
Data | x | FLOOR_Value |
---|---|---|
Data 1 | -10.75 | -11 |
Data 2 | -5.38 | -6 |
Data 3 | 0.98 | 0 |
Data 4 | 13.16 | 13 |
Data 5 | 48.13 | 48 |
❮ PostgreSQL Functions