y=round(x)y = \operatorname{round}(x)

Graph of the Rounding Function y=round(x)y = \operatorname{round}(x)

y=round(x)y = \operatorname{round}(x) rounds xx to the nearest integer1. A fractional part below 0.50.5 is discarded and one above 0.50.5 is rounded up.

xxround(x)\operatorname{round}(x)
2.32.322
2.62.633
1.2-1.21-1
1.6-1.62-2

Domain and range

The domain is all real numbers and the range is the set of all integers. The graph is a staircase of horizontal segments of width 11, each sitting over an interval centered on an integer.

IntervalValue
0.5<x<0.5-0.5 < x < 0.500
0.5<x<1.50.5 < x < 1.511
1.5<x<2.51.5 < x < 2.522

For the floor and ceiling functions the breaks between steps fell on the integers; for rounding they fall on the half-integers. Because each step is centered on its integer, the error of the rounding is as small as it can be.

Discontinuities and the rounding convention

The function is discontinuous at the half-integers x=n+0.5x = n + 0.5, the exact midpoints, where the value jumps by 11. Which way those midpoints go is fixed by convention.

Conventionround(0.5)\operatorname{round}(0.5)round(1.5)\operatorname{round}(1.5)round(2.5)\operatorname{round}(2.5)
Round half up112233
Round half to even, or banker's rounding002222

Statistics and accounting often use rounding to even, to avoid a bias toward rounding up. Implementations differ over negative numbers and midpoints, so it is safest to check before relying on one.

Symmetry

Away from the half-integers round(x)=round(x)\operatorname{round}(-x) = -\operatorname{round}(x) holds, so the graph has broadly point symmetry about the origin. Only at the midpoints can the convention break that symmetry.

Relation to other functions

Under the round-half-up convention it can be written with the floor function.

round(x)=x+0.5\operatorname{round}(x) = \lfloor x + 0.5 \rfloor

Rounding is thus a sibling of the floor and ceiling functions: it amounts to choosing whichever of x\lfloor x \rfloor and x\lceil x \rceil lies closer to xx.

xxx\lfloor x \rfloorx\lceil x \rceilround(x)\operatorname{round}(x)
2.32.3223322
2.72.7223333
1.2-1.22-21-11-1

Applications

  • Displaying an amount of money
  • Matching the number of digits of a measurement
  • The quantization of a digital signal

It is used wherever a continuous value has to be rounded to an integer that is easier to handle.

  1. Rounding, Wikipedia