Nearest Integer Function — Definition, Formula & Examples
The nearest integer function rounds a real number to the closest integer. When the fractional part is exactly 0.5, the convention typically rounds to the nearest even integer (called banker's rounding), though some textbooks round up.
For a real number , the nearest integer function returns the integer that minimizes . If lies exactly halfway between two consecutive integers (i.e., the fractional part equals ), the tie-breaking rule varies by convention — commonly rounding to the nearest even integer or rounding away from zero.
Key Formula
Where:
- = Any real number to be rounded
- = The floor function (greatest integer less than or equal to the argument)
How It Works
To evaluate , look at the fractional part of . If it is less than , round down to the integer below. If it is greater than , round up to the integer above. If the fractional part is exactly , apply whichever tie-breaking rule your course specifies. The graph of this function is a step function with jumps occurring at each half-integer value (e.g., ).
Worked Example
Problem: Find nint(3.7), nint(−2.3), and nint(4.5).
Step 1: For 3.7, the fractional part is 0.7, which is greater than 0.5, so round up.
Step 2: For −2.3, the fractional distance to −2 is 0.3 and to −3 is 0.7, so the nearest integer is −2.
Step 3: For 4.5, the value is exactly halfway between 4 and 5. Using the round-half-up convention: round up to 5. Using round-half-to-even: the nearest even integer is 4.
Answer: nint(3.7) = 4, nint(−2.3) = −2, and nint(4.5) = 5 or 4 depending on the tie-breaking convention.
Why It Matters
Rounding to the nearest integer shows up in computer science (pixel coordinates, signal processing) and statistics (reporting whole-number counts). In precalculus, it provides practice with piecewise and step functions and helps you understand discontinuities at half-integer points.
Common Mistakes
Mistake: Confusing the nearest integer function with the floor (greatest integer) function.
Correction: The floor function always rounds down: . The nearest integer function rounds to whichever integer is closer: . They differ whenever the fractional part exceeds 0.5.
