The 'round' function's round direction is down for certain half numbers but up for others

The ‘round’ function is to rounds numbers.

For example, we expect numbers that are greater than 0 and less than 0.5 (e.g. 0.1, 0.2, etc.) to become 0 and numbers that are greater than or equal to 0.5 and less than 1 to become 1.

But it does the round calculation according to so called ‘banker’s rounding’, This means that all the halves (e.g. 0.5, 1.5, 2.5, etc.) are rounded to the nearest even number like below.

Let’s say we have data like below,

And we use the ‘round’ function like below.

Then, we’ll end up getting the result like below.

You notice that the number like 2.5 doesn’t round up to 3, instead it rounds down to 2.

If you want all the halves to round up to the next number you can use another function called ‘round_half_up’.


The result would be something that most of us expect.

This is an R function from ‘Janitor’ package, which is installed/loaded by default so that you can use it right away in Exploratory.

Janitor Package: Link
round_half_up function: Link

1 Like