+ 2

What should I do to convert input float to integer in python??

23rd Mar 2018, 3:31 AM
Amaan
Amaan - avatar
6 ответов
+ 3
If x is your float you could use int(x) or round(x)... They don't exactly give the same results though. int(x) keeps the integer part and get rid of the decimal part while round(x) rounds it up to the nearest integer Take a look at this for examples https://code.sololearn.com/cxTO8C65udMh/?ref=app
23rd Mar 2018, 3:50 AM
cyk
cyk - avatar
+ 3
Take a look at my code again. Added some more examples to address your problem
23rd Mar 2018, 4:12 AM
cyk
cyk - avatar
+ 3
For more detailed information about all sorts of type conversions in Python, check out this link :) https://www.digitalocean.com/community/tutorials/how-to-convert-data-types-in-python-3
23rd Mar 2018, 4:19 AM
cyk
cyk - avatar
+ 2
:) You are very welcome!
23rd Mar 2018, 4:29 AM
cyk
cyk - avatar
+ 1
I got it! Thanks to you buddy:)
23rd Mar 2018, 4:28 AM
Amaan
Amaan - avatar
0
thank you:) @Yemibk I'm having a slight trouble in my code which I've posted if you would take a look when a float input is given it returns a ValueError
23rd Mar 2018, 4:03 AM
Amaan
Amaan - avatar