Integer expression | Sololearn: Learn to code for FREE!

+1

Integer expression

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

2/2/2017 7:29:54 PM

Efraim Ié

5 Answers

New Answer

+2

tried this two on Ubuntu, first is int 12, second 12 in float.

+2

2.4 in int is 2, then 5*2=10.

+2

int(2.4) chops off the ".4"

+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

+1

sorry guys I mean, the second expression is: int (5)* int (2.4) =10 Why 10 and not 12