1 point

Converting float numbers to integer in Python


dashboard

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

Posted by @happycardstwo #python #numbers

>>> int(3.7)
3

>>> int(-3.4)
-3

>>> int(round(3.8))
4
content_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.



>> Browse more code snippets

more_vert