simple question I assume, but I just stumbled across this:
float y=2+2/3;
Output: 2
How come float cannot process 2/3? My guess is that float interprets 2/3 as integers. But how come it accepts 2 in the beginning?
simple question I assume, but I just stumbled across this:
float y=2+2/3;
Output: 2
How come float cannot process 2/3? My guess is that float interprets 2/3 as integers. But how come it accepts 2 in the beginning?
That's integer division. You're basically computing:
float y = 2 + (2 / 3);
float y = 2 + (0 );
float y = 2;
Try:
float y = 2 + 2.0 / 3;