Round to the nearest integer, returning a DOUBLE, using banker's rounding.
RINT(expr)
## Overview Returns the input rounded to the nearest integer as a DOUBLE, using round-half-to-even (banker's rounding). Unlike ROUND without a scale argument, RINT always returns a DOUBLE, which is useful when the result feeds directly into further floating-point math and you want to avoid implicit casts. RINT mirrors the behavior of the IEEE 754 rint intrinsic and is numerically equivalent to BROUND(x, 0). ## Behavior - Accepts any finite DOUBLE value. - Returns a DOUBLE representing the nearest integer value. - Returns NULL if the argument is NULL. - Uses round-half-to-even at exact halfway values. - The output is always an integer-valued DOUBLE (for example, 4.0, -3.0). ## Numeric precision - Uses the IEEE 754 double-precision rint routine, which is exact for any input that is already an integer. - For large magnitudes above 2^53, every DOUBLE is already an integer; RINT returns the input unchanged in that regime. - Matches BROUND(x, 0) for all inputs. ## Compatibility - Matches the C99 and IEEE 754 rint convention. - Equivalent to BROUND(x, 0) in engines that provide both.
| Name | Type | Description |
|---|---|---|
expr | Specifies the numeric value to round to the nearest integer. Accepts any finite DOUBLE value. |
-- Round 4.3 down
SELECT RINT(4.3);
-- Result: 4.0
-- Round 4.7 up
SELECT RINT(4.7);
-- Result: 5.0
-- Halfway 2.5 rounds to 2 (even)
SELECT RINT(2.5);
-- Result: 2.0
-- Halfway 3.5 rounds to 4 (even)
SELECT RINT(3.5);
-- Result: 4.0
-- Negative halfway -2.5 rounds to -2 (even)
SELECT RINT(-2.5);
-- Result: -2.0
-- NULL propagation
SELECT RINT(NULL);
-- Result: NULL