FLOOR() Examples in SQL Server

InĀ SQL Server, the T-SQL FLOOR() function allows you to round a number down to the nearest integer. More specifically, it returns the largest integer less than or equal to the specified numeric expression.

You provide the number as an argument. The return data type is the same as the one provided as an argument.

Syntax

The syntax goes like this:

FLOOR ( numeric_expression )   

Where numeric_expression is an expression of the exact numeric or approximate numeric data type category.

Note that the bit data type is invalid.

Example 1 – Positive Values

Here’s an example of providing a positive value as the argument.

SELECT FLOOR(3.63) Result;

Result:

+----------+
| Result   |
|----------|
| 3        |
+----------+

In this case, 3 is the largest integer less than or equal to 3.63.

Here’s another example, this time with a larger value.

SELECT FLOOR(500.71) Result;

Result:

+----------+
| Result   |
|----------|
| 500      |
+----------+

Example 2 – Negative Values

Here’s an example using a negative value.

SELECT FLOOR(-3.63) Result;

Result:

+----------+
| Result   |
|----------|
| -4       |
+----------+

In this case, -4 is the largest integer less than or equal to -3.63.

Here’s another example.

SELECT FLOOR(-500.71) Result;

Result:

+----------+
| Result   |
|----------|
| -501     |
+----------+

Rounding Up – CEILING()

If you prefer to round up to the nearest integer, use the T-SQL CEILING() function instead.