+ 1
why isn't int("2.5") not working while float("2") works??
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.
+ 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.
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