PostgreSQL 18 reference · Math Functions

PostgreSQL FLOOR() Function

Round a number down to the nearest integer: floor(2.9) is 2 and floor(-2.1) is -3.

PostgreSQL 18

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

floor(x)

Parameters

ParameterDescription
x A number (integer, numeric or double precision).

Return value

A number of the input type.

Examples

Round down
SELECT floor(2.9) AS a, floor(-2.1) AS b;

Output

 a | b
---+----
 2 | -3
(1 row)

Run this on your computer — see “Get Started” for setup.

Price bands
SELECT floor(price / 10) * 10 AS band, count(*) AS products
FROM products
GROUP BY band
ORDER BY band
LIMIT 4;

Output

 band | products
------+----------
    0 |        1
   10 |        1
   20 |        2
   30 |        2
(4 rows)

Run this on your computer — see “Get Started” for setup.

In other languages

Was this page helpful?