我有一个存储经度和纬度坐标的表格(谷歌地图)我将列定义为浮点数但是当我尝试插入一个值-61.45859899999999和10.28289时,它们将四舍五入为-61.46和10.30.如何修改列以保持数据不变.
CREATE TABLE `tblGeoCodes` (
`recNo` int(11) NOT NULL AUTO_INCREMENT,`longLocation` float(30,2) DEFAULT NULL,`latLocation` float(30,2) DEFAULT NULL
最佳答案
您的实施有两个问题.
原文链接:https://www.f2er.com/mysql/434235.html将值四舍五入为2位精度的原因是您明确将比例定义为2.
此外,FLOAT是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,-> `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)