A nearest integer to x∈Rx\in\mathbb R is an integer nn minimizing the ∣x−n∣|x-n|. It always satisfies ∣x−n∣≤1/2|x-n|\le1/2. The minimizer is unique unless xx is halfway between two consecutive integers.

A convention

One deterministic rule is n(x)=⌊x+1/2⌋n(x)=\lfloor x+1/2\rfloor, which resolves a tie toward the larger integer. Other rules, such as rounding ties to an even integer, must be specified if used. A nearest nonzero integer minimizes over Z∖{0}\mathbb Z\setminus\{0\} and can differ from ordinary rounding near zero; a tie between −1-1 and 11 occurs at zero.

Example

The nearest integer to 2.32.3 is 22, while both 22 and 33 minimize distance to 2.52.5. Rounding is a discrete selection operation, so differentiability cannot be assumed at the selection boundaries.