0
2 / 3 == 0 ?
I found that out when I was doing code challenges. When I try printing 2/3, it says 0. I tried rounding it but it still says 0. Why?
2 Réponses
+ 6
Int numbers have no decimals, so if you divide 5/2, you'll get 2, not 2.5.
You can write 2/3.0 or 2.0/3, then auto-conversion to type double occurs.
0
Because they are integers .
any number between two integers is round to the smaller one and get printed that is how it works. E.g 0.5,0.1,0.9...are all between 0 and 1 then they round into 0. Hence they are equal in the concept of integers.