Search code examples
mysqldatabasetypesfloating-pointsqldatatypes

How to store precise decimal degree coordinates in a MySQL database


I've created a database using the store locator tutorial on Google Code, which specifies that the fields to store marker coordinates be of type FLOAT(10,6). However, when I geocode certain points using Google's geocoder service I get some results with 14 decimal places. For example,

-70.07290899999998

The numbers are never more than 21 or less than -67 and always have between 1 and 14 digits after the decimal point.

How do I set this field in the database?


Solution

  • Don't use float; use fixed point. Float by nature is rough.

    http://dev.mysql.com/doc/refman/5.0/en/fixed-point-types.html

    3 before, 15 after DECIMAL(17,14)