user1996496 user1996496 - 2 months ago 8
MySQL Question

How do I properly insert latitude & longitude coordinates into mySQL float?

I am trying to insert something like

150.1835024
and
32.8392648
into mySQL as
float
. The problem is when I try to create a mySQL field like
FLOAT 3,7
it doesn't work. What's the proper format?

This is the error I get:

An error occurred when trying to add the field 'location_lat' via

ALTER TABLE `data` ADD `location_lat` FLOAT(3,7)
NULL
DEFAULT NULL
AFTER `fees`

MySQL said: For float(M,D), double(M,D) or decimal(M,D),
M must be >= D (column 'location_lat').

Answer

Look at the error as it says MySQL said: For float(M,D) .. M must be >= D and with that your query should actually be

ALTER TABLE `data` ADD `location_lat` FLOAT(7,3)

Go through MySQL Documentation On Floating-Point Types

MySQL permits a nonstandard syntax: FLOAT(M,D). Here, (M,D) means than values can be stored with up to M digits in total, of which D digits may be after the decimal point.

Comments