Description of MySQL Data Type decimal (m, d)
For instructions on MySQL Data Type decimal (m, d), perform the following test on your own:
Create table decimal_test (
Id int auto_increment PRIMARY key,
Score decimal (999.99) -- value range:-999.99
);
-- The number of digits of an integer must be smaller than or equal to m-d. Otherwise, an error is returned. The number of decimal places can be greater than d. When there are more d bits, it will be rounded in and truncated to d bits.
-- The preceding values do not contain the decimal point or the number of digits of the symbol. The total length of a number is m bits, and the maximum number of decimal places after saving is d bits. If it is an integer after saving, the decimal places do not add 0.
-- The following test version is 5.7.14
Select * from decimal_test;
-- Positive:
Insert into decimal_test (score) VALUES (1.23); -- 1.23
Insert into decimal_test (score) VALUES (123.45); -- 123.45
Insert into decimal_test (score) VALUES (123.455); -- 123.46
Insert into decimal_test (score) VALUES (123.451); -- 123.45
Insert into decimal_test (score) VALUES (123.451123); -- 123.45
Insert into decimal_test (score) VALUES (12345.451123); -- Out of range value for column 'score'
Insert into decimal_test (score) VALUES (9999.451123); -- Out of range value for column 'score'
Insert into decimal_test (score) VALUES (999.451123234324); -- 999.45
Insert into decimal_test (score) VALUES (999.999999999); -- Out of range value for column 'score'
Insert into decimal_test (score) VALUES (999.99123); -- 999.99
-- Negative number:
Insert into decimal_test (score) VALUES (-1.23); ---1.23
Insert into decimal_test (score) VALUES (-12.34); ---12.34
Insert into decimal_test (score) VALUES (-123.45); ---123.45
Insert into decimal_test (score) VALUES (-999.45); ---999.45
Insert into decimal_test (score) VALUES (-12343); -- Out of range value for column 'score'
Insert into decimal_test (score) VALUES (12343); -- Out of range value for column 'score'
Insert into decimal_test (score) VALUES (1234); -- Out of range value for column 'score'
Insert into decimal_test (score) VALUES (123); -- 123
Insert into decimal_test (score) VALUES (-123); ---123
Insert into decimal_test (score) VALUES (-999.99); ---999.99
Insert into decimal_test (score) VALUES (-9990.99); -- Out of range value for column 'score'
Insert into decimal_test (score) VALUES (-1234.99); -- Out of range value for column 'score'
Insert into decimal_test (score) VALUES (-1234); -- Out of range value for column 'score'
Select VERSION (); -- 5.7.14