> ## Documentation Index
> Fetch the complete documentation index at: https://docs.firebolt.io/llms.txt
> Use this file to discover all available pages before exploring further.

> Reference material for FLOOR function

# FLOOR

export const QueryWindow = ({content}) => {
  const {sql, result} = content;
  const [inited, setInited] = useState(false);
  const buttonRef = useRef(null);
  useEffect(() => {
    if (!inited && buttonRef.current) {
      runQuery(buttonRef.current, true);
      setInited(true);
    }
  }, []);
  return <div className="query-window">
      <div className="query-toolbar">
        <button className="run-button" onClick={ev => runQuery(ev.target)} ref={buttonRef}>Run Query</button>
        <span className="window-title">Interactive SQL Playground 🔥</span>
      </div>
      <div className="query-content">
        <pre><code className="firebolt-sql language-sql" contentEditable="true" spellCheck="false" data-original-query={sql}>{sql}</code></pre>
        <script type="application/json" className="fallback-result" style={{
    display: "none"
  }}>{JSON.stringify(result)}</script>
        <div className="server-unavailable-banner query-window-hidden">
          The Firebolt playground server is currently unavailable. Using precomputed query results.
        </div>
        <div className="query-results"></div>
      </div>
    </div>;
};

Rounds an input `<value>` down to the nearest multiple based on the specified precision or decimal place. Optionally, you can specify a second parameter to determine which decimal place the value should be rounded down to.

## Syntax

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
FLOOR(<value>);
FLOOR(<value>, <digit>);
```

## Parameters

| Parameter | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          | Supported input types         |
| :-------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :---------------------------- |
| `<value>` | The number to be rounded down to the nearest specified place.                                                                                                                                                                                                                                                                                                                                                                                                                                                        | `NUMERIC`, `DOUBLE PRECISION` |
| `<digit>` | (Optional) You can specify a second parameter to define the position of the digit to round down to, based on its distance from the decimal point. Positive numbers indicate digits after the decimal, while negative numbers refer to digits before the decimal. For example, `1` rounds down to the first digit after the decimal, and `-1` rounds down to the nearest ten. A value of `0` rounds down to the nearest whole number. The default is `0`, which means that rounding down happens at the whole number. | `INTEGER`                     |

## Return Type

| Input Type         | Output Type                                  |
| :----------------- | :------------------------------------------- |
| `NUMERIC`          | `NUMERIC` with same `precision` and `scale`. |
| `DOUBLE PRECISION` | `DOUBLE PRECISION`                           |

## Remarks

When the input is of type `NUMERIC`, `FLOOR` throws an overflow error if the result of `FLOOR` exceeds the defined precision and scale limits of the return data type.

The following code example calculates the nearest whole number smaller than `-99.99` and specifies that the output should contain a total of `4` digits, with only `2` digits reserved for the decimal part:

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
SELECT FLOOR(-'99.99'::NUMERIC(4,2));
```

**Returns**

The previous code returns an `OVERFLOW ERROR` because `FLOOR` returns `-100.00`, which exceeds the `NUMERIC(4,2)` data type's limit of `2` digits before the decimal point, and `-100` requires `3` digits.

## Examples

The following example returns the nearest whole number smaller than `2.5549900`:

<QueryWindow
  content={{
"sql": "SELECT FLOOR(2.5549900);",
"result": {
"data": [
  [
    2
  ]
],
"meta": [
  {
    "name": "?column?",
    "type": "double"
  }
],
"query": {
  "query_id": "58eaa8f8-1725-4042-af96-176af6bd8fb5",
  "query_label": null,
  "request_id": "8cd3b04b-d046-44a5-97f7-3e2e6c13766c"
},
"rows": 1,
"statistics": {
  "bytes_read": 1,
  "elapsed": 0.006613,
  "rows_read": 1,
  "scanned_bytes_cache": 0,
  "scanned_bytes_storage": 0,
  "time_before_execution": 0.000246446,
  "time_to_execute": 9.5034e-05
}
}
}}
/>

The following example calculates the nearest whole number smaller than `213.1549`, and returns a result of type `NUMERIC(20,4)`, which allows for a total of 20 digits, with 4 values allowed after the decimal point:

<QueryWindow
  content={{
"sql": "SELECT FLOOR('213.1549'::NUMERIC(20,4));",
"result": {
"data": [
  [
    213.0
  ]
],
"meta": [
  {
    "name": "?column?",
    "type": "Decimal(20, 4)"
  }
],
"query": {
  "query_id": "9a963275-0733-488e-b6f5-2b4e8620682a",
  "query_label": null,
  "request_id": "92d5bb16-1044-40c5-a6d3-a63f8298ee54"
},
"rows": 1,
"statistics": {
  "bytes_read": 1,
  "elapsed": 0.006548,
  "rows_read": 1,
  "scanned_bytes_cache": 0,
  "scanned_bytes_storage": 0,
  "time_before_execution": 0.000249736,
  "time_to_execute": 8.4897e-05
}
}
}}
/>

The following code example rounds the number `2.5549900` down to the second decimal place.
It returns `2.55` because the second parameter 2 specifies rounding to the second digit after the decimal, which corresponds to the hundredths place.

<QueryWindow
  content={{
"sql": "SELECT FLOOR(2.5549900, 2);",
"result": {
"data": [
  [
    2.55
  ]
],
"meta": [
  {
    "name": "?column?",
    "type": "double"
  }
],
"query": {
  "query_id": "64432b0d-dee0-47fc-8cd8-3b6c7eab657d",
  "query_label": null,
  "request_id": "0eccd91e-fa66-4d5b-b7b3-90d4f1f8bf32"
},
"rows": 1,
"statistics": {
  "bytes_read": 1,
  "elapsed": 0.008378,
  "rows_read": 1,
  "scanned_bytes_cache": 0,
  "scanned_bytes_storage": 0,
  "time_before_execution": 0.000246263,
  "time_to_execute": 8.6045e-05
}
}
}}
/>

The following example calculates the nearest whole number smaller than `1998` that is a multiple of `1000`.
It returns `1000` because the second parameter -3 specifies rounding to the third digit before the decimal point, which corresponds to the thousands place.

<QueryWindow
  content={{
"sql": "SELECT FLOOR(1998, -3);",
"result": {
"data": [
  [
    1000
  ]
],
"meta": [
  {
    "name": "?column?",
    "type": "double"
  }
],
"query": {
  "query_id": "fa73f8f3-8534-4806-ac90-5d71ae9877fd",
  "query_label": null,
  "request_id": "d1686c9f-7f01-4011-b0ac-3e288da51a52"
},
"rows": 1,
"statistics": {
  "bytes_read": 1,
  "elapsed": 0.007125,
  "rows_read": 1,
  "scanned_bytes_cache": 0,
  "scanned_bytes_storage": 0,
  "time_before_execution": 0.000244076,
  "time_to_execute": 9.1033e-05
}
}
}}
/>
