BigQuery · Math function
BigQuery FLOOR
FLOOR(x) returns the largest whole number that is not greater than x: FLOOR(2.9) is 2.0 and FLOOR(-2.1) is -3.0. Use it to round down and to build fixed-width bins and time buckets that stay correct for negative values. INT64 and FLOAT64 inputs return FLOAT64.
FLOOR rounds down toward negative infinity. For positive values it drops the fraction; for negative values it moves away from zero, which is where it differs from TRUNC: FLOOR(-2.1) is -3.0 while TRUNC(-2.1) is -2.0.
The pattern FLOOR(x / width) * width puts values into fixed-width bins that stay correct for negative numbers, and FLOOR(UNIX_SECONDS(ts) / 300) * 300 builds 5-minute time buckets. DIV returns INT64 directly, but it truncates toward zero, so it only matches FLOOR when the quotient is not negative.
FLOOR has no digits argument; use FLOOR(x * 100) / 100 on NUMERIC values to round down to cents. On FLOAT64 the same expression can lose a cent: 0.29 * 100 is 28.999999999999996, so the result is 0.28. INT64 and FLOAT64 inputs return FLOAT64; NUMERIC and BIGNUMERIC keep their type.
Syntax
FLOOR(X)Arguments and return value
| Argument | Description |
|---|---|
X | INT64, NUMERIC, BIGNUMERIC or FLOAT64. |
Returns: FLOAT64 for INT64 or FLOAT64 input, NUMERIC for NUMERIC and BIGNUMERIC for BIGNUMERIC.
Examples
Round down positive, negative and integer values
SELECT
FLOOR(2.9) AS down,
FLOOR(-2.1) AS negative,
FLOOR(5) AS from_int64;| down | negative | from_int64 |
|---|---|---|
| 2.0 | -3.0 | 5.0 |
Bins that handle negative values
FLOOR puts -12.5 in the bin from -20 to -10. TRUNC rounds negative quotients toward zero, so -12.5 lands in the -10 bin and the bin around zero becomes twice as wide.
WITH readings AS (
SELECT temp_c FROM UNNEST([-25.0, -12.5, 4.2, 17.9]) AS temp_c
)
SELECT
temp_c,
FLOOR(temp_c / 10) * 10 AS floor_bin,
TRUNC(temp_c / 10) * 10 AS trunc_bin
FROM readings
ORDER BY temp_c;| temp_c | floor_bin | trunc_bin |
|---|---|---|
| -25.0 | -30.0 | -20.0 |
| -12.5 | -20.0 | -10.0 |
| 4.2 | 0.0 | 0.0 |
| 17.9 | 10.0 | 10.0 |
5-minute time buckets
UNIX_SECONDS turns the timestamp into seconds. FLOOR snaps it to a multiple of 300, and TIMESTAMP_SECONDS turns it back, which needs an INT64.
WITH events AS (
SELECT TIMESTAMP '2026-11-23 10:03:59 UTC' AS event_ts UNION ALL
SELECT TIMESTAMP '2026-11-23 10:04:10 UTC' UNION ALL
SELECT TIMESTAMP '2026-11-23 10:07:30 UTC'
)
SELECT
TIMESTAMP_SECONDS(CAST(FLOOR(UNIX_SECONDS(event_ts) / 300) * 300 AS INT64)) AS bucket_start,
COUNT(*) AS events
FROM events
GROUP BY bucket_start
ORDER BY bucket_start;| bucket_start | events |
|---|---|
| 2026-11-23 10:00:00 UTC | 2 |
| 2026-11-23 10:05:00 UTC | 1 |
Round down to cents: FLOAT64 vs NUMERIC
0.29 is stored as 0.28999999999999998 in FLOAT64, and multiplying by 100 gives 28.999999999999996.
SELECT
FLOOR(0.29 * 100) / 100 AS float64_result,
FLOOR(NUMERIC '0.29' * 100) / 100 AS numeric_result;| float64_result | numeric_result |
|---|---|
| 0.28 | 0.29 |
Common mistakes
- Using FLOOR to drop decimals from negative numbers.
FLOOR(-2.5)is -3.0; use TRUNC to cut toward zero. - Assuming DIV rounds down.
DIV(-7, 2)is -3 (toward zero) whileFLOOR(-7 / 2)is -4.0. - Expecting INT64.
FLOOR(5)returns 5.0; wrap it inCAST(... AS INT64)before using it as a key or passing it to TIMESTAMP_SECONDS. - Rounding FLOAT64 down to decimals.
FLOOR(0.29 * 100) / 100returns 0.28; use NUMERIC.
FAQ
What is the difference between FLOOR and TRUNC in BigQuery?
They match for positive numbers. For negative numbers FLOOR rounds down (FLOOR(-2.5) is -3.0) and TRUNC rounds toward zero (TRUNC(-2.5) is -2.0).
How do I round down to 2 decimal places?
Use FLOOR(x * 100) / 100 with x as NUMERIC to avoid FLOAT64 errors. For values that are never negative, TRUNC(x, 2) gives the same result.
How do I group timestamps into 15-minute buckets?
Use TIMESTAMP_SECONDS(CAST(FLOOR(UNIX_SECONDS(ts) / 900) * 900 AS INT64)). For whole units such as hour or day, TIMESTAMP_TRUNC is simpler.
Related
More mathematical functions
All BigQuery mathematical functions · All functions · BigQuery error messages
