Description of MySQL Data Type decimal (m, d)

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.