Answer the question
In order to leave comments, you need to log in
Difference in FLOAT(M,D) behavior in versions 4.0 and 5.1?
I am transferring the database from the server to
4.0.24-standard-log (it is on Red Hat 9.0)
to the server
5.1.50-log FreeBSD port: mysql-server-5.1.50
And I ran into such a problem that some fields are unloaded as FLOAT[8 ,6], and all values are truncated to 100.000000 when pasted. Although in the old version there were also large values. Conducted an experiment:
In version 4.0
mysql> create table test (amount float(8,6) NOT NULL default '0.000000');
Query OK, 0 rows affected (0.02 sec)
mysql> insert into test values(1000);
Query OK, 1 row affected (0.00 sec)
mysql> select * from test;
+-------------+
| amount |
+-------------+
| 1000.000000 |
+-------------+
1 row in set (0.00 sec)
mysql> create table test (amount float(8,6) NOT NULL default '0.000000');
Query OK, 0 rows affected (0.00 sec)
mysql> insert into test values(1000);
Query OK, 1 row affected, 1 warning (0.00 sec)
mysql> select * from test;
+------------+
| amount |
+------------+
| 100.000000 |
+------------+
1 row in set (0.00 sec)
where SUBSTRING(timefrom,1,6)=201012
Answer the question
In order to leave comments, you need to log in
I recently ran into a similar problem. This article helped . If FLOAT in your database is used to store "business" values (money, etc.) then use the DECIMAL type. In all other cases, use DOUBLE.
FLOAT should be avoided at all costs. it is more prone to calculation errors. “Funny” is the situation when, after adding an integer value to the database, when selecting the same record, you get some units in the ninth digit.
in the case of decimal this is unlikelyo_0?
mysqldump | sed (меняем FLOAT(8,6) на FLOAT ) | mysql
if it's Windows, then it's better to install cygwin. Sorry if my advice is like "thank you, cap", it's just that it's not very clear from your question what exactly is the problem with replacing FLOAT(8,6) with FLOAT
Not for the sake of argument, but purely for sharing information :)
CREATE TABLE digits (
float_col FLOAT DEFAULT NULL,
decimal_col DECIMAL(20,18) DEFAULT NULL,
double_col DOUBLE DEFAULT NULL
) ENGINE=INNODB DEFAULT CHARSET=cp1251
INSERT INTO digits VALUES( ( @pi := 3.141592653589793238 ) / 3, @pi / 3, @pi / 3 );
UPDATE digits SET float_col = float_col * 3 - @pi, decimal_col = decimal_col * 3 - @pi, double_col = double_col * 3 - @pi;
float_col decimal_col double_col 1.0472 1.047197551196597746 1.0471975511965979
float_col decimal_col double_col 0.0000000874228 0.000000000000000000 4.440892098500626e-16
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question