MySQL FLOOR() Function
The FLOOR()
function in MySQL rounds a number *down* to the nearest integer. This means it removes any fractional part of the number without any rounding up.
FLOOR(): Definition and Usage
FLOOR()
is useful when you need to work with whole numbers and want to discard the decimal portion of a number. It's particularly handy in situations where you need to perform calculations based on integer values.
Related Functions
For related mathematical operations, explore these MySQL functions: ROUND()
(rounds to the nearest integer or specified decimal place), CEIL()
/CEILING()
(rounds up to the nearest integer), TRUNCATE()
(truncates to a specified number of decimal places), and DIV
(integer division).
Syntax
Syntax
FLOOR(number)
Parameter Values
Parameter | Description |
---|---|
number |
The number you want to round down to the nearest integer. This is a required numeric value. |
Examples
Rounding Down a Decimal Number
This example demonstrates rounding 25.75 down to 25.
Syntax
SELECT FLOOR(25.75);
Output
25
Rounding Down a Whole Number
When the input is already an integer, FLOOR()
simply returns the same number.
Syntax
SELECT FLOOR(25);
Output
25