E
E
Evgeny Ivanov2018-01-31 12:21:25
MySQL
Evgeny Ivanov, 2018-01-31 12:21:25

What does DECIMAL (MySql) data/field type mean?

I set a field in the database - my_value DECIMAL(11,10). It is necessary to store values ​​of the form 123456789.1234567890
As I understand it, this field should store a value with 11 integer digits and 10 fractional digits.
But this, of course, is not the case. The fractional part is stored, but the whole is not.
What do the numbers in this DECIMAL(11,10) notation even mean?
And why would an entry like DECIMAL(9,10) cause an error
Query error: #1427 - For float(M,D), double(M,D) or decimal(M,D), M must be >= D (column 'coin_value ').
PS

Sponsor of stupid questions not clear manuals

salary DECIMAL(5,2)
В этом примере - 5 (точность) представляет собой общее количество (а есть не общее?) значащих десятичных знаков (значащих знаков? масло масленое?), с которыми будет храниться данная величина (а может и не храниться?), а цифра 2 (масштаб) задает количество десятичных знаков после запятой (ну хоть это понятно).

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Maxim Fedorov, 2018-01-31
@logpol32

DECIMAL(X,Y)
X - the total number of characters in the number (including the fractional part)
Y - the number of characters in the fractional part

M
Melkij, 2018-01-31
@melkij

the total (is there not a total?)

yes there is - the number of decimal places.
Yes, it may not be stored. In particular - discard, round or give an overflow error.
No.
There are 11 characters in total, 10 of them are for the fractional part.
Because the number of decimal places cannot be greater than the total number of decimal places.

V
Vitaly Kuzminov, 2018-07-17
@Vito300187

For example, in Rails there is an option to determine the number of integers, the number of fractional numbers after the decimal point, the total number of numbers of the input number based on MySql:
precision - determines the number of digits in the number before the decimal point
scale - determines the number of digits in the number after the decimal point
decimal - determines the total number of digits in a number

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question