Here is the test:
- First I create a field with float(11, 9) and insert a number 0.12345679, when selecting this row, it shows 0.123456791;
- Second I alter the field to float(11, 4) and select it out, it shows 0.1235;
- Third I alter the field back to float(11, 9) and get the number, it shows 0.123456791;
Why the action changing field precision would not lose the data's precision, and wondering why.
mysql> create table `test`.`test_float`(id int primary key auto_increment, `num` float(11, 9));
Query OK, 0 rows affected, 1 warning (0.03 sec)
mysql> insert into test.test_float(num) values(0.123456789);
Query OK, 1 row affected (0.00 sec)
mysql> select * from test.test_float\G
*************************** 1. row ***************************
id: 1
num: 0.123456791
1 row in set (0.00 sec)
mysql> alter table test.test_float modify num float(11, 4);
Query OK, 0 rows affected, 1 warning (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 1
mysql> select * from test.test_float\G
*************************** 1. row ***************************
id: 1
num: 0.1235
1 row in set (0.00 sec)
mysql> alter table test.test_float modify num float(11, 9);
Query OK, 0 rows affected, 1 warning (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 1
mysql> select * from test.test_float\G
*************************** 1. row ***************************
id: 1
num: 0.123456791
1 row in set (0.00 sec)