Stop Making This Database Mistake with Decimal Values

preview_player
Показать описание

We often need to store decimal values in our database, for things like money or scores.

Most databases have data types to store these decimals.

But there's a better way to store decimal data, and I'll explain what it is and why in this video.

⏱ TIMESTAMPS:
00:00 - Using decimals
01:00 - The problem and solution

🔗 VIDEO LINKS:
Рекомендации по теме
Комментарии
Автор

And in case you want to model an order where X units is sold for a total of Y, then you might want the price to be modelled as a rational number with an integer numerator and an integer denominator.

RAMPKORV
Автор

I don't see how it changes anything. Isn't Decimal(8, 2) just saying that it is a fixed-point decimal and the length is 8, and the last 2 digits are after the decimal point? What if with the int solution we want to add 123.442 as in the example? We still cannot do it and it must be rounded. If we want to update the schema to allow more precision, then we can do it with decimal too by updating to Decimal(9, 3) for example.

Pezsmapatkany
visit shbcf.ru