1 point

Converting float numbers to integer in Python


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

Posted by @happycardstwo #python #numbers

>>> int(3.7)

>>> int(-3.4)

>>> int(round(3.8))
content_copy Copy

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.