Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing decimal number with MySQL

Tags:

sql

mysql

What's the best type to store values such:

48.89384 and -2.34910

Actually I'm using float.

like image 265
Cheerio Avatar asked Dec 07 '25 12:12

Cheerio


1 Answers

Use decimal for exact values.

Notes:

  • ABS (Latitude) <= 90
  • ABS (Longitude) <= 180

So you can us 2 different types

  • Latitude = decimal (x+2, x)
  • Longitude = decimal (y+3, y)

x and y will be the desired precision. Given a metre is 1/40,000,000 of the earth's circumferemce, something like 6-8 will be enough depending on whether you're going for street or full stop accuracy in location.

like image 177
gbn Avatar answered Dec 10 '25 03:12

gbn