ROUND(number, [decimals]) rounds to the given number of decimal places, or to a whole number when decimals is left out. A half rounds away from zero: 2.5 becomes 3 and -2.5 becomes -3. DuckDB's round(), Snowflake's and BigQuery's do the same. The hand-rolled floor(x + 0.5) rounds -2.5 up to -2.
Updated · Checked on the xmetric engine
What is the syntax?
ROUND(number, [decimals])
number
the number to round.
decimals
optional: how many decimal places to keep. 0 or omitted rounds to an integer; a negative value rounds to tens, hundreds and so on.
Returns a number rounded to decimals places (a whole number if decimals is omitted). Null if the input is null.
What does it return, and what is the SQL?
Each example runs on the same 8 sample rows twice: the Tableau formula on the xmetric engine, and the SQL in DuckDB.
What is each value rounded to a whole number?
Tableau
ROUND([Value])
SQL (DuckDB)
SELECTround(Value) AS result
FROM input
ORDERBY id
2.5 becomes 3, -2.5 becomes -3 and 3.75 becomes 4.
Value
Result
2.5
3
−2.5
−3
0.13
0
−0.4
0
3.75
4
null
0
0
16
16
✓ The Tableau formula and the SQL return the same 8 rows.
What is each value rounded to one decimal?
Tableau
ROUND([Value], 1)
SQL (DuckDB)
SELECTround(Value, 1) AS result
FROM input
ORDERBY id
3.75 becomes 3.8 and 0.125 becomes 0.1.
Value
Result
2.5
2.5
−2.5
−2.5
0.13
0.1
−0.4
−0.4
3.75
3.8
null
0
0
16
16
✓ The Tableau formula and the SQL return the same 8 rows.
Where does a straight translation go wrong?
Common mistake
Why does floor(x + 0.5) round -2.5 the wrong way?
Adding a half and flooring sends every half upward: -2.5 becomes -2. Tableau rounds halves away from zero, to -3.
Tableau
ROUND([Value])
Tempting SQL
SELECTfloor(Value +0.5) AS result
FROM input
ORDERBY id
SQL that matches
SELECTround(Value) AS result
FROM input
ORDERBY id
Value
Tableau
Tempting SQL
SQL that matches
2.5
3
3
3
−2.5
−3
−2
−3
0.13
0
0
0
−0.4
0
0
0
3.75
4
4
4
null
null
null
0
0
0
0
16
16
16
16
✓ The SQL that matches returns the Tableau result on every row; the marked cells are where the tempting SQL differs.
What does each precision return?
The same values with decimals omitted and with two decimals. Columns 1 to 8 are the sample rows, by id.
Case
Tableau, then SQL (DuckDB)
1
2
3
4
5
6
7
8
default precision
ROUND([Value])round(Value)
3
−3
0
0
4
null
0
16
two decimals
ROUND([Value], 2)round(Value, 2)
2.5
−2.5
0.13
−0.4
3.75
null
0
16
✓ On every row, each Tableau formula and its SQL return the same value.
How do I write it in Snowflake or BigQuery?
The first example, written for each warehouse from its documentation. These are not run here; DuckDB is.
Snowflake
SELECTROUND(Value) AS result
FROM input
ORDERBY id
Away from zero: 2.5 becomes 3 and -2.5 becomes -3. It isn't banker's rounding.
Why does 9.405 round to 9.40?
Floating point stores 9.405 as slightly less than 9.405, so ROUND(9.405, 2) gives 9.4. Tableau's help notes the same; format the number instead if you only need it displayed.
Can decimals be negative?
ROUND([Value], -1) rounds to tens: 16 becomes 20. DuckDB accepts this too.