MySQL storing Floats

回眸只為那壹抹淺笑 提交于 2019-12-06 08:27:28

问题


I am trying to save a float number which is this long

13.00386644742523

Its basically Lat and Lng value. when i save it in the database its getting stored as

13.0039


回答1:


Based on experience I did this for a navigation database built from ARINC424 and eventually used a DECIMAL(18,12) for storing values in radians.

NOTE: Floats and doubles aren't as precise and may result in rounding errors

The point is that when using degrees or radians we know the range of the values - and the fractional part needs the most digits.

The best way is to use MySQL Spatial Extensions




回答2:


You should use the precision explicitly and the type should be DECIMAL NOT FLOAT as every digit after decimal point is significant and you cant let they allow to be changed because of rounding.

`lat`  DECIMAL(16,14)

Read on manual




回答3:


I think your data type for the the column is defined as Float(N,4) where N is the number and 4 is the number of decimal places allowed. That is why it is rounding the stored value.

The best way to store Lat/Long is to use spatial data type. POINT geometry type will hold your values



来源:https://stackoverflow.com/questions/11185997/mysql-storing-floats

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!