What is the ideal data type to use when storing latitude / longitude in a MySQL database?

前端 未结 21 2739
梦如初夏
梦如初夏 2020-11-22 09:40

Bearing in mind that I\'ll be performing calculations on lat / long pairs, what datatype is best suited for use with a MySQL database?

21条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-22 10:14

    A FLOAT should give you all of the precision you need, and be better for comparison functions than storing each co-ordinate as a string or the like.

    If your MySQL version is earlier than 5.0.3, you may need to take heed of certain floating point comparison errors however.

    Prior to MySQL 5.0.3, DECIMAL columns store values with exact precision because they are represented as strings, but calculations on DECIMAL values are done using floating-point operations. As of 5.0.3, MySQL performs DECIMAL operations with a precision of 64 decimal digits, which should solve most common inaccuracy problems when it comes to DECIMAL columns

提交回复
热议问题