FLOOR() Function in PostgreSQL is used to round down the value.
- Get Round down value in PostgreSQL – FLOOR()
- Create the column which extracts the round down value i.e. Floor of the column in the PostgreSQL table
Syntax for FLOOR() Function in PostgreSQL:
SELECT floor(number_or_expression);
number_or_expression: This is the number or expression for which you want to round down or find the floor value to it.
FLOOR() Function in PostgreSQL:
FLOOR() function in PostgreSQL returns the round down value, i.e. the largest integer value that is less than or equal to a specified number.
Example 1:
SELECT FLOOR(4.56);
Output:
Example 2:
SELECT FLOOR(-3.14);
Output:
Floor() function (Round down value) of the column in PostgreSQL :
you can use floor() function within a SELECT statement to calculate the largest integer less than or equal to each value in the column. Here’s how you can do it with the help of an example
bookkit:
Example 1:
Creating the column which extracts the round down value i.e. Floor of the column in the PostgreSQL table is shown
select *,floor(charges) as floor_charges from bookkit
- ”floor(charges)” calculates the largest integer less than or equal to each charges.
- ”AS floor_charges” assigns an alias ”floor_charges” to the calculated floor value.
So the output will be
Output:
Round down only for the positive valued column in Postgresql
Example 1 – using Floor() function:
We will be rounding down only the positive column in the example let’s take “price” column.
select *,floor(price) as floor_price from bookkit
Output:
Example 2 – using TRUNC() function:
We will be using TRUNC() function rounding down only the positive column in the example let’s take “price” column.
select *,TRUNC(price) as floor_price from bookkit
The truncate function will get the largest integer less than or equal to each value in the column,
Note: This function is applicable only when the entire column has positive Values
Output: