Wait… what? We got a
0? After all these years of being taught it's
Has someone deceived us? Not really.
What happened here is called integer division. Integer division occurs when both the dividend and the divisor are integers. Since they are integers, SQL Server wants to return an integer result to match the operand types. In other words, it brutally cuts off the decimal part, which is
.25 in our case. The zero (
0) is the only thing left.
So, how can we make sure that the result includes the decimal part? One way is to change the type of one of the values to a decimal (e.g.,
1 / 4.0 instead of
1 / 4). In this course, we will always change the type of the counter.