A good question. I thought the entire number was supposed to reside in the
database but only 2 decimals displayed. The number resides in my database
(Version 3.23.51-nt) as 2 decimals. Apparently because your '0.005' goes in
as text it is being truncated to 2 decimals when it goes in. Since the 0.005
goes in as a number it is apparently rounded before it goes into the
This could be of use if, for example, you wanted to make your numbers
significant to the 2nd decimal, you should enter them as text.
A more knowledgeable explanation or confirmation would be appreciated.
> Gerald Clark writes:
> Why do you find this surprising?
> You defined the field to have 2 deciimal places..
> Matt Loschert wrote:
> >I have quick question about rounding and/or truncation of a decimal table
> >field. I ran into this unexpectedly and found it surprising.
> >Given the following input:
> > DROP TABLE IF EXISTS test1;
> > CREATE TABLE test1 (id tinyint, truncated decimal(12,2));
> > INSERT INTO test1 VALUES (1, '0.004');
> > INSERT INTO test1 VALUES (2, 0.004 );
> > INSERT INTO test1 VALUES (3, '0.005');
> > INSERT INTO test1 VALUES (4, 0.005 );
> > SELECT * FROM test1;
> > SELECT VERSION();
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe: http://lists.mysql.com/mysql?unsub=1