# Definition:Rounding/Integer

< Definition:Rounding(Redirected from Definition:Rounding to Nearest Integer)

Jump to navigation
Jump to search
## Definition

Let $x \in \R$ be a real number.

Let $y \in \R$ such that:

- $y = \left\lfloor{x + \dfrac 1 2}\right\rfloor$

Then $y$ is defined as **$x$ rounded to the nearest integer**.

## Treatment of Half

Consider the situation when $\dfrac x {10^n} + \dfrac 1 2$ is an integer.

That is, $\dfrac x {10^n}$ is exactly midway between the two integers $\dfrac x {10^n} - \dfrac 1 2$ and $\dfrac x {10^n} + \dfrac 1 2$.

Recall that the general philosophy of the process of rounding is to find the closest approximation to $x$ to a given power of $10$.

Thus there are two equally valid such approximations:

- $\dfrac x {10^n} - \dfrac 1 2$ and $\dfrac x {10^n} + \dfrac 1 2$

between which $\dfrac x {10^n}$ is exactly midway.

The convention on $\mathsf{Pr} \infty \mathsf{fWiki}$ is that the greater of the two is used:

- $y = 10^n \left\lfloor{\dfrac x {10^n} + \dfrac 1 2}\right\rfloor$

but other systems exist.

## Sources

- 1997: Donald E. Knuth:
*The Art of Computer Programming: Volume 1: Fundamental Algorithms*(3rd ed.) ... (previous) ... (next): $\S 1.2.4$: Integer Functions and Elementary Number Theory: Exercise $5$