+ 1

why isn't int("2.5") not working while float("2") works??

18th Aug 2016, 1:50 PM
chundru srilekha
chundru srilekha - avatar
3 Réponses
+ 4
When you convert a string to an integer, the string has to be a 'real' integer like "25" or "4" because Python is not able to convert a 'float-string' into a integer. When Python converts a float to a integer it cuts all after the decimal point. For example int (2.9)=2. You see, you have to be careful with this. Compared with this, integer to float causes in Python no problems.
18th Aug 2016, 5:34 PM
Amarie
+ 3
conversation from float to int is a downcast of variables, that is why it is not implicitly done by python. to make it work, we need to explicitly cast it to int. int(float("2.3")) will give you integer 2.
18th Aug 2016, 9:43 PM
Amit Gupta
Amit Gupta - avatar
0
float is larger then int while integer only act without decimal point from negative to positive but float having integrated integer which will serve as integer and its original operations. of float integer with decimal value
16th Dec 2016, 2:10 PM
omprakash prajapati
omprakash prajapati - avatar