i have a column like decimal(2,1) , its working well, but when i try to store a value like 10 it stores as 9.9 ..any specific reason?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes, when you say 2,1 what you really say is: this column can store two digits, and one of them can be after the decimal point.
If you would like to be able to save 10.1 you would use DECIMAL(3,1), since 10.1 is 3 digits total.
It will throw a warning, BTW:
mysql> SHOW CREATE TABLE t\G
*************************** 1. row ***************************
Table: t
Create Table: CREATE TABLE
t(adecimal(2,1) DEFAULT ‘0.0’) ENGINE=InnoDB DEFAULT CHARSET=latin1
1 row in set (0.00 sec)
mysql> INSERT INTO t (a) VALUES (10);
Query OK, 1 row affected, 1 warning (0.00 sec)
mysql> SHOW WARNINGS\G
*************************** 1. row ***************************
Level: Warning
Code: 1264–
Message: Out of range value for column ‘a’ at row 1
1 row in set (0.00 sec)
mysql>
—
Edit: And when running in STRICT mode (http://dev.mysql.com/doc/refman/5.0/en/server-sql-mode.html#sqlmode_traditional) it will actually throw a warning.