MySql using the Float data type to store geographic coordinates

I have a table that stores the coordinates of longitude and latitude (google maps). I have columns defined as float , but when I try to insert the values ​​-61.45859899999999 and 10.28289, they are rounded to - 61.46 and 10.30. How can I change the columns to store data as is.

I am using mysql toad . Sub - table code:

CREATE TABLE `tblGeoCodes` (
  `recNo` int(11) NOT NULL AUTO_INCREMENT,
  `longLocation` float(30,2) DEFAULT NULL,
  `latLocation` float(30,2) DEFAULT NULL 
+5
source share
4 answers

There are two problems with your implementation.

The reason the values ​​are rounded to two digits of accuracy is because you explicitly defined the scale as 2.

In addition, FLOAT is an inaccurate data type in MySQL.

, DECIMAL .

, - :

CREATE TABLE `tblGeoCodes` (
  `recNo` int(11) NOT NULL AUTO_INCREMENT primary key,
  `longLocation` decimal(18,14) DEFAULT NULL,
  `latLocation` decimal(18,14) DEFAULT NULL
); 

:

mysql> CREATE TABLE `tblGeoCodes` (
    ->   `recNo` int(11) NOT NULL AUTO_INCREMENT primary key,
    ->   `longLocation` decimal(18,14) DEFAULT NULL,
    ->   `latLocation` decimal(18,14) DEFAULT NULL
    -> ); 
Query OK, 0 rows affected (0.02 sec)

mysql> 
mysql> insert into tblGeoCodes (longLocation,latLocation) values(-61.45859899999999 , 10.28289);
Query OK, 1 row affected (0.00 sec)

mysql> 
mysql> select * from tblGeoCodes;
+-------+--------------------+-------------------+
| recNo | longLocation       | latLocation       |
+-------+--------------------+-------------------+
|     1 | -61.45859899999999 | 10.28289000000000 |
+-------+--------------------+-------------------+
1 row in set (0.00 sec)
+13

,2 float(30,2) 2 . float(10,6), ,

+5

MYISAM, GSI. .

, , float . Google, Google dev.

0

Mention that FLOAT(10,6)it makes no sense, it reserves 4 digits for the whole part.

Personally, I prefer DOUBLE(9,6), but instead, you can use FLOATto save 4 extra bytes.

0
source

All Articles