3
I’m writing a program in Python and I came up with a question here. Before coming to ask I searched for "Python Rounding" here on Sopt and found two old questions with the subject, but both did not answer my question.
That question here How to "round" a float in Python? talks about the function round
that I already know, but she does not answer me, because the function round
works always rounding to the nearest number, let’s see the examples:
a = 5.92
b = round(a,0)
print(b)
The result shown will be 6.
a = 5.22
b = round(a,0)
print(b)
The result shown will be 5. That is, it only rounds down if the decimal fraction was below 0.5.
I also found this question How to round up with Python?, that addresses the function ceil
, that makes rounding upwards. As I wish to round down, this, of course, also does not suit me, because let’s look at the examples:
from math import ceil
a = 5.92
b = ceil(a)
print(b)
The result shown will be 6.
from math import ceil
a = 5.22
b = ceil(a)
print(b)
The result shown will also be 6.
The question is: Which function rounds down in Python?
It worked here, thank you!
– Cadu