Canonical: https://knowlpedia.com/shared-foundations/nearest-integer/

# Nearest integer

An integer minimizing distance to a given real number, with a stated tie convention.

A **nearest integer** to \(x\in\mathbb R\) is an integer \(n\) minimizing the [absolute value](https://knowlpedia.com/real-analysis/absolute-value/) \(|x-n|\). It always satisfies \(|x-n|\le1/2\). The minimizer is unique unless \(x\) is halfway between two consecutive integers.

## A convention

One deterministic rule is \(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 \(\mathbb Z\setminus\{0\}\) and can differ from ordinary rounding near zero; a tie between \(-1\) and \(1\) occurs at zero.

## Example

The nearest integer to \(2.3\) is \(2\), while both \(2\) and \(3\) minimize distance to \(2.5\). Rounding is a discrete selection operation, so differentiability cannot be assumed at the selection boundaries.
