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
Syntax
floor(x)
Parameters
| Parameter | Description |
|---|---|
x |
A number (integer, numeric or double precision). |
Return value
A number of the input type.
Examples
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.
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
FLOOR()· SQLite
Related
CEIL()· Round a number up to the nearest integer: ceil(2.1) is 3 and ceil(-2.1) is -2. ceiling() is a synonym.TRUNC()· Truncate a number toward zero, optionally keeping some decimal places: trunc(2.789, 2) is 2.78.WIDTH_BUCKET()· Return which of n equal-width buckets a value falls into between a low and high bound, for building histograms.- SQL Aggregate Functions · tutorial