Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

float and double datatype is good to store latitude and longitude? [duplicate]

I am storing latitude and longitude at the server side (JAVA Platform).

To store those values, I am using float and double datatype at the server side. I came to know that float and double are not a recommended primitive datatypes (which is not recommended to use currencies in professional way), because float and double having rounding precision problem.

In my case, I am just comparing the stored coordinates (latitude and longitude) at the server side.

Question 1:

Comparing the coordinates with the datatypes (float or double) will make any problem in future?

Question 2:

Using big decimal is good? or Going with float or double is safer?

like image 862
ArunRaj Avatar asked Dec 18 '13 11:12

ArunRaj


People also ask

Should latitude longitude be float or double?

you will not have to do any rounding on your longitude or latitude values, so use whichever one you want. Double is more precise, so let that be the most important factor in your decision.

Which datatype is used for latitude and longitude?

p. precision you should use DECIMAL . Latitudes range from -90 to +90 (degrees), so DECIMAL(10,8) is ok for that, but longitudes range from -180 to +180 (degrees) so you need DECIMAL(11,8) .

How do you store longitude and latitude?

Longitude and latitude coordinates are stored with 15 decimal digits right of the decimal points.

Which of the following is the best data type to store latitude and longitude coordinates that are in decimal degrees?

The most precise available option is DOUBLE . The most common seen type used is DECIMAL(8,6)/(9,6) .


3 Answers

You should start with the accuracy you desire. Once you have determined that, you can choose a data type that is suitable.

If you decide that an accuracy of 5 decimal places (1.1132 m) is enough, you can easily go with float. The more accurate your calculation needs to be, the more you should lean towards using double and eventually BigDecimal.

When comparing floating point numbers, you should incorporate the necessary precision as well.

like image 81
Kai Sternad Avatar answered Oct 13 '22 20:10

Kai Sternad


It's not a matter of safety, its just a matter of precision. I wouldn't consider floats, but doubles are what i think are ideal here. You just need to see what's the most precision you can get out of a double and see if it fits a regular longitude/latitude value. I think it's more then enough.

Else BigDecimal is just a simple backdoor to your problem, use it if you want more precision

like image 30
ThaBomb Avatar answered Oct 13 '22 20:10

ThaBomb


you will not have to do any rounding on your longitude or latitude values, so use whichever one you want. Double is more precise, so let that be the most important factor in your decision.

How much precision do your long/lat values need?

For pinpoint accuracy on a map, you might want to look at big decimal, but for vague values, float is good enough.

like image 27
Husman Avatar answered Oct 13 '22 18:10

Husman