+ 1

Integer expression

int (5*2.4) =12 int (5)*(2.4) =10 Why this expression gives different results?

2nd Feb 2017, 7:29 PM
Efraim Ié
Efraim Ié - avatar
5 Respuestas
+ 2
tried this two on Ubuntu, first is int 12, second 12 in float.
2nd Feb 2017, 7:35 PM
Ruslan Ovcharenko
Ruslan Ovcharenko - avatar
+ 2
2.4 in int is 2, then 5*2=10.
2nd Feb 2017, 8:21 PM
Ruslan Ovcharenko
Ruslan Ovcharenko - avatar
+ 2
int(2.4) chops off the ".4"
2nd Feb 2017, 8:22 PM
Tab Smart
Tab Smart - avatar
+ 1
Because int(5*2.4) converts 12.0 to an integer, int(5)*(2.4) only converts 5 to int. THEN multiply it by 2.4, and gives you 12.0 as a float
2nd Feb 2017, 8:11 PM
Tab Smart
Tab Smart - avatar
+ 1
sorry guys I mean, the second expression is: int (5)* int (2.4) =10 Why 10 and not 12
2nd Feb 2017, 8:19 PM
Efraim Ié
Efraim Ié - avatar