The way the python int()
function works rounds a number to the smallest value.
Such that 4.99 = 4
What can I do if I want 4.99 be equal to 5?
The way the python int()
function works rounds a number to the smallest value.
Such that 4.99 = 4
What can I do if I want 4.99 be equal to 5?
int()
truncates float values, removing the non-integral portion of the number. You are looking for rounding instead.
You can use the round()
function for that:
>>> round(4.99)
5
math.ceil
and math.floor
return floats which are the nearest whole numbers above or below the parameter.