Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Review
So you think you can count?
Rounding functions and more
Review and practice

Instruction

Wait... what? We got a 0? After being taught it's 0.25? Has someone deceived us?

Not really.

What happened here is called integer division. This occurs when both the dividend and the divisor are integers. Since they are integers, PostgreSQL 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 denominator.

Exercise

Run another example query to see what happens when you use a decimal number.