Rounding functions
Rounding functions choose a nearby representable number. The direction matters for negative values: floor moves toward negative infinity, while truncation moves toward zero.
Syntax
text
round(value [, digits])
ceil(value)
ceiling(value)
floor(value)
trunc(value)Behavior
| Function | Rule |
|---|---|
round |
Round to a number of decimal places; the default is zero. |
ceil / ceiling |
Choose the least integer value greater than or equal to the input. |
floor |
Choose the greatest integer value less than or equal to the input. |
trunc |
Remove the fractional part toward zero. |
Ordinary floating-point round uses half-away-from-zero ties and clamps its requested decimal places to 0 through 30. Floating-point values remain approximate.
Decimal rounding preserves the declared scale. A carry into an additional integer digit can widen its precision to the next supported family. SQL NULL propagates.
Examples
Comparing directions
sql
SELECT round(12.345, 2), ceil(1.2), floor(-1.2), trunc(-1.2)
FORMAT csv;text
12.35,2.0,-2.0,-1.0Exact decimal rounding
sql
SELECT round(CAST('12.345' AS Decimal(18, 3)), 2)
FORMAT csv;text
12.350See Decimal and floating-point types for precision and conversion rules.