Knowledge base / SQL
ROUND in SQL: precision, numeric types and operation order
I explain how numeric types and the stage of rounding change the result, including negative decimal-place arguments.

ROUND rounds a numeric value to a chosen position. I use it when the calculation should actually acquire a different value rather than merely look shorter on screen. Before adding it to a report, I establish the engine, numeric type and stage of rounding. Those three decisions can explain differences between summaries that initially look identical.
The following examples are synthetic. The main variant uses PostgreSQL 18 and numeric; SQL Server and MySQL 8.4 are labelled separately. I do not assume that every database and every numeric representation share one rule.
Positive, zero and negative second arguments
In PostgreSQL, the two arguments specify the value and number of decimal places. A negative second argument moves the rounding position to the left of the decimal point:
SELECT ROUND(CAST(12.346 AS NUMERIC), 2) AS result;
The value is 12.35: the third fractional digit is 6, so the hundredths increase by one. Changing the second argument to 1 gives 12.3; using 0 gives 12. The PostgreSQL mathematical functions documentation describes round(numeric, integer) and how exact halfway cases are resolved.
| PostgreSQL 18 expression | Result value |
|---|---|
ROUND(12.346::numeric, 2) |
12.35 |
ROUND(12.346::numeric, 1) |
12.3 |
ROUND(12.346::numeric, 0) |
12 |
ROUND(12345::numeric, -1) |
12350 |
ROUND(12345::numeric, -2) |
12300 |
When rounding 12345 to tens, the input lies exactly between 12340 and 12350. This rule selects 12350. Rounding to hundreds gives 12300 because 45 is less than half a hundred. The negative argument specifies a rounding position; it is not a general instruction to retain a particular number of significant figures.
What happens exactly halfway
For PostgreSQL numeric, ties are rounded away from zero. ROUND(2.5::numeric, 0) has value 3 and ROUND(-2.5::numeric, 0) has value -3. For negative inputs, describing this as always moving towards the larger number would be misleading. The sign matters when explaining the direction.
Approximate numbers need different assumptions. The PostgreSQL numeric types documentation distinguishes numeric from real and double precision. Halfway behaviour for floating-point types can depend on the platform, with nearest-even rounding being common. I would not promise that an arbitrary floating-point input behaves identically to an exact decimal numeric value.
The MySQL 8.4 documentation also separates exact and approximate inputs. When comparing systems, inspect the real input type rather than only the displayed value. A cell that appears to contain 2.5 does not establish all the assumptions needed to reproduce the calculation in another environment.
PostgreSQL: two arguments require NUMERIC
PostgreSQL provides a one-argument form for double precision, but the form specifying decimal places takes numeric. If measurement is a double precision column, I can deliberately choose:
SELECT ROUND(CAST(measurement AS NUMERIC), 2)
FROM readings;
This performs conversion and rounding rather than just changing display. Casting an approximate value does not automatically recover its original measurement accuracy. If the source requires exact decimal values, consider the type in the data model itself. The function argument conversion chapter also explains the resolution of the two-argument round form.
SQL Server: a required position and truncation option
In T-SQL, the position argument is required. Do not transfer a rule that omission means zero from another database. SQL Server additionally accepts a third argument: a nonzero value selects truncation instead of rounding. These examples are for that engine:
SELECT ROUND(CAST(12.346 AS DECIMAL(6,3)), 2) AS rounded;
SELECT ROUND(CAST(12.346 AS DECIMAL(6,3)), 2, 1) AS truncated;
The values are 12.35 and 12.34 respectively. A client may display an extra zero because the scale is retained. Microsoft also documents overflow when the rounded value does not fit the input type. The function does not automatically provide an arbitrarily large target. Before rounding to thousands, check that a possible carry into the next order of magnitude will fit.

ROUND, truncation and rounding down
For -2.7 in PostgreSQL, floor gives -3 while trunc gives -2. The first chooses the nearest integer no greater than the input; the second removes the fractional part towards zero. round(-2.7::numeric, 0) gives -3, but matching floor for one input does not make the functions interchangeable.
Truncation names differ by engine: PostgreSQL uses trunc, MySQL uses truncate, and the T-SQL example uses ROUND with a third argument. Choose the documented operation for your goal. Similarly, casting to an integer type should not replace an explicit rounding rule.
Round the total or round the components
Take two exact synthetic values: 0.014 and 0.014. Their sum is 0.028, which rounds to 0.03 at two decimal places. If each component is rounded first, the values become 0.01 and 0.01. Their sum is 0.02. Both paths are internally consistent, but they perform different operations.
Consequently, ROUND(SUM(value), 2) and SUM(ROUND(value, 2)) are not interchangeable. Establish whether the individual records or final aggregate should be rounded before implementing the measure. This is a result-definition decision. Do not select the variant after seeing which figure better matches an expectation. Record the operation order beside the measure when handing the report over.
Rounding can also merge different values into one group. Grouping by a rounded measurement deliberately loses some resolution. For presentation alone, the receiving tool’s display format may be sufficient. ROUND changes the value and can therefore affect later sums, filters and comparisons. Choose it because the transformation is intended, not simply because a shorter number looks tidier on a chart.
Exercise: describe the rule first
Choose a small positive value, a negative one and an exact halfway case. Record the engine, data type, position and stage of rounding. Work out the two neighbouring permitted results by hand, then choose the function. If the report must follow a different business rule, adding ROUND without agreeing that rule is not enough to establish a correct calculation.
Key takeaways
What is ROUND(12345, -1)?
In the PostgreSQL NUMERIC example, the value is 12350. A negative second argument rounds to the tens position.
Why does two-argument ROUND fail for double precision in PostgreSQL?
The form accepting decimal places takes NUMERIC. An explicit cast can select it, but cannot restore accuracy already lost in the source.
Is rounding a sum the same as summing rounded values?
Not necessarily. Two values of 0.014 sum and round to 0.03, while rounding them individually before summing gives 0.02.
AI was used in an automated way while working on this article. If you want to learn how to do it too, check out this project.
