I have this in a mysql table:
id
and bolag_id
are int
. lat
and lngitude
are double
.
If I use the the lngitude
column, no results are returned:
lngitude
Query: SELECT * FROM location_forslag WHERE
lngitude= 13.8461208
However, if I use the lat
column, it does return results:
lat
Query: SELECT * FROM location_forslag WHERE
lat= 58.3902782
What is the problem with the lngitude
column?
Convert float to decimal for compare. I had the same problem and solved like this:
Look at the first 3 rows after the WHERE clausule. Hope it helps.
It is not generally a good idea to compare floating point numbers with
=
equals operator.Is it correct to compare two rounded floating point numbers using the == operator?
Dealing with accuracy problems in floating-point numbers
For your application, you need to consider how close you want the answer to be.
1 degree is about 112km, and 0.00001 degrees is about 1.1 metres (at the equator). Do you really want your application to say "not equal" if two points are different by 0.00000001 degrees = 1mm?
This will return points where lngitude is within
@epsilon
degrees of the desired value. You should choose a value for epsilon which is appropriate to your application.Floating points are irritating....