MySQL FLOOR() Function: Round downward to an integer

FLOOR() returns the greatest integer that is less than or equal to the supplied number.

FLOOR(): Quick SQL Example

Run this SELECT query directly in MySQL or phpMyAdmin. It uses fixed inputs so you can verify the result without creating a table.

SELECT FLOOR(-5.2) AS floor_value;
floor_value
-6
On this page — Show page sectionsHide page sections

More SQL Examples and Explanations

SELECT FLOOR(80.41);  -- 80
Floor MySQL function returns the largest integer that is not greater than the input value. This can be easily understood by some examples.
SELECT FLOOR(5.89);   -- 5
SELECT FLOOR(5.22);   -- 5
SELECT FLOOR(-5.89);  -- -6
SELECT FLOOR(-5.12);  -- -6
As you can see in above command gives largest integer that is not greater than the input value.

We will apply our floor command to our student table. We will take average ( avg ) value of all marks secured by students and to that we will apply floor command. Let us first try without floor.
SELECT AVG(mark) AS avg_mark FROM student;
Output = 74.6571

Now we can use floor command like this.
SELECT FLOOR(AVG(mark)) AS avg_mark FROM student;
Output = 74

How to Interpret the Result

For negative inputs, FLOOR() moves toward negative infinity. Compare CEIL() for the opposite direction.

Common Question

Is FLOOR(-5.2) equal to -5?
No. FLOOR(-5.2) returns -6 because -6 is the largest integer not exceeding -5.2.

Further Reading

All Math Functions CEIL()

More related tutorials: All math functions, AVG()

↑ Back to top




Subscribe to our YouTube Channel here



plus2net.com
kathir

07-06-2012

Thanks for your kind work




SQL Video Tutorials










✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer