I was looking for a function which, given a float, will return an int of the float floored or rounded to the nearest int. Is there such a thing built-in or available in a module?
The following code does the trick but I avoid reinventing the wheel.
import math
def realround(number):
_, d = divmod(number, 1)
if d > 0.5:
return int(math.ceil(number))
else:
return int(math.floor(number))
print(realround(12.3))
print(realround(14.5))
print(realround(15.8))