How to store latitudes and longitudes in MySQL?

I am trying to keep latitude 39.8162994 and longitude -98.5576019 as a float, but it turns out as 0.00000000000 and -98.55760192871 , respectively.

What is the problem? I use float(15,11) as a data type.

+4
source share
2 answers

You should DECIMAL(10,7) use DECIMAL(10,7) to keep the longitude value with 7 decimal places: Β±179.1234567 . The FLOAT data type is used to represent approximate values ​​for numeric data, where, on the other hand, you can instead store exact values ​​with the DECIMAL data DECIMAL .

+6
source

I would recommend you use DECIMAL or save it as a whole with a known offset (say 10e-7 ).

Use at least as many digits as you need:

 DECIMAL(15,12) 
+3
source

Source: https://habr.com/ru/post/1303047/


All Articles