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?

8th Apr 2020, 1:43 PM
Mustafa K.
Mustafa K. - avatar
3 Respostas
+ 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.
8th Apr 2020, 2:04 PM
HonFu
HonFu - avatar
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.
9th Apr 2020, 1:14 PM
D ̲E ̲S ̲S ̲I ̲E ̲- ̲B ̲A ̲H ̲I ̲R ̲U ̲
D ̲E ̲S ̲S ̲I ̲E ̲- ̲B ̲A ̲H ̲I ̲R ̲U ̲ - avatar