MySQL numeric functions
MySQL string functions
MySQL Date/Time functions
MySQL aggregate functions
MySQL flow control functions
The FLOOR()
function in MySQL is used to round down a number to the nearest integer. This means it will always return the largest integer less than or equal to the input number.
The syntax for FLOOR()
is:
FLOOR(number)
Where number
is the numeric value you want to round down.
Here's an example of using FLOOR()
:
SELECT FLOOR(1.9);
This will return '1', because 1.9 rounded down to the nearest integer is 1.
Here's another example:
SELECT FLOOR(-1.9);
This will return '-2', because -1.9 rounded down is -2.
You can also use FLOOR()
with columns in a table. For example, if you have a table named 'products' with a column 'price', you can get the floor value of each price like this:
SELECT product_id, FLOOR(price) AS floor_price FROM products;
This would return a result with the product ID and the floor price for each product.
Remember that the FLOOR()
function always rounds down, regardless of the fraction of the number. If you want to round to the nearest integer (up or down), you should use the ROUND()
function instead.
MySQL FLOOR Function Example:
FLOOR
function in MySQL is used to round a numeric value down to the nearest integer.-- Example of using FLOOR SELECT FLOOR(15.75) AS rounded_down_value;
FLOOR vs CEIL in MySQL:
FLOOR
(round down) and CEIL
(round up) functions.-- Example comparing FLOOR and CEIL SELECT FLOOR(15.75) AS rounded_down_value, CEIL(15.75) AS rounded_up_value;
Examples of FLOOR Function in MySQL:
FLOOR
is applied to round down numeric values.-- Additional examples of using FLOOR SELECT FLOOR(10.5) AS example1, FLOOR(25.8) AS example2, FLOOR(-5.3) AS example3;