Request a demo

BigQuery reference

BigQuery mathematical functions

Mathematical functions round, divide, bucket and transform numbers. Watch the input type: INT64, NUMERIC and FLOAT64 behave differently on rounding, overflow and division by zero.

Functions in this category

FunctionWhat it does
ABSABS(x) returns the absolute value of x with the same type as the input: ABS(-42) is 42.
CEIL / CEILINGCEIL(x) returns the smallest whole number that is not less than x: CEIL(2.1) is 3.0 and CEIL(-2.9) is -2.0.
DIVDIV(x, y) divides two integers and drops the remainder: DIV(7, 2) is 3, while 7 / 2 is 3.5.
FLOORFLOOR(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.
GREATESTGREATEST(x1, x2, ...) returns the largest of its arguments within a single row, for example the latest of several date columns.
LEASTLEAST(x1, x2, ...) returns the smallest of its arguments within a single row, such as the earliest of several dates or a value capped at a limit.
LOG, LN, LOG10LOG(x) returns the natural logarithm of x (the same as LN), LOG(x, base) uses any base, and LOG10(x) uses base 10.
MODMOD(x, y) returns the remainder of x divided by y, with the sign of x: MOD(25, 7) is 4 and MOD(-25, 7) is -4.
POW / POWERPOW(x, y) raises x to the power y, and POWER is a synonym: POW(2, 10) returns 1024.0.
RANDRAND() returns a pseudo-random FLOAT64 from 0 (inclusive) to 1 (exclusive), different for every row and every run.
RANGE_BUCKETRANGE_BUCKET(point, boundaries) returns the 0-based index of the bucket a value falls into, given a sorted array of boundaries: RANGE_BUCKET(25, [10, 20, 30]) is 2.
ROUNDROUND(x, n) rounds x to n decimal places, with halfway cases going away from zero: ROUND(19.987, 2) returns 19.99.
SAFE_DIVIDESAFE_DIVIDE(x, y) divides x by y like the / operator but returns NULL instead of failing when y is 0 or the division overflows.
SQRTSQRT(x) returns the square root of x: SQRT(16) is 4.0.
TRUNCTRUNC(x, n) cuts x to n decimal places by rounding toward zero: TRUNC(2.789, 2) is 2.78 and TRUNC(-2.789, 2) is -2.78.

More of the BigQuery reference

Observability for every BigQuery table, in about 15 minutes

Masthead detects freshness, volume and schema anomalies, monitors pipeline errors and maps column-level lineage across all your projects, from logs and metadata only.