Introduction
Numbers
Boolean
Date and time
Summary

Instruction

Excellent! See how convenient these numbers are? There is, however, one problem about REAL and DOUBLE numbers which you must take into account. These are rounding errors. Why?

Well, DOUBLE 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 finite 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 rounded as well - you can predict what happens.

Exercise

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

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

Stuck? Here's a hint!

Type

SELECT height, weight, 
height - weight - height + weight AS expected_zero 
FROM body 
WHERE user_id = 6;

Console

Code editor

Result

TableConsole