Reputation: 980
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').
Upvotes: 0
Views: 530
Reputation: 142298
Do not use FLOAT(m,d)
, simply use FLOAT
. The former adds an extra round that buys you nothing.
A FLOAT
takes 4 bytes in either case.
Upvotes: 0
Reputation: 1738
The first number is the total number of digits, both the the right and to the left of the decimal. The second number is how many digits you want to the right of the decimal. So you're looking for:
ALTER TABLE `data` ADD `location_lat` FLOAT(10,7)
Upvotes: 3
Reputation: 77876
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.
Upvotes: 3