Integer and float numbers - Learn Python 3 - Snakify

Lesson 2. Integer and float numbers




5/10. Round and round

You can also cast float objects to int objects. Of course, it can be achieved using the int() function, which simply discards the fractional part (rounding, thus, every number towards 0).

But, generally, it is much more convenient to use round(), which performs that rounding we are used to.

Instructions

Click "Run" to see what happens in output!

print(int(1.3))   # gives 1
print(int(1.7))   # gives 1
print(int(-1.3))  # gives -1
print(int(-1.7))  # gives -1

print(round(1.3))   # gives 1
print(round(1.7))   # gives 2
print(round(-1.3))  # gives -1
print(round(-1.7))  # gives -2