Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Numerical data types
Integer data types
Floating point data types
10. Floating point numbers – issues with precision
Decimal data types
Summary

Instruction

Excellent! See how convenient these numbers are? Still, there is one problem with real and double precision numbers that you must take into account: rounding errors. Why do these happen?

Well, double precision and real numbers store information in the binary system. Values such as 0.2 don't have a precise binary representation. Numbers like 1/3 can't be represented with a precise decimal number at all. This is why such numbers need to be rounded. And when you add a rounded number to a rounded number, and the result is also rounded – well, you can guess what happens.

Exercise

Have you noticed that we have a rather special user in our table? The one with user_id 6? It's Thumbelina. We will use the information she provided to check rounding errors.

Select her height and weight and calculate the third column called expected_zero in the following way: height - weight - height + weight. It should equal zero, right?

Stuck? Here's a hint!

Remember about the condition:

WHERE user_id = 6;