Converting float numbers to integer in Python


PHOTO EMBED

Thu Feb 06 2020 19:00:00 GMT+0000 (UTC)

Saved by @happycardstwo #python #numbers

>>> int(3.7)
3

>>> int(-3.4)
-3

>>> int(round(3.8))
4
content_copyCOPY

Note: the first two methods do not round off the number. They only truncate the float up till the decimal point. Use the 3rd method (line 7), to first round off the number and then convert to integer. This should work in all versions of Python.