Question

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?

Was it helpful?

Solution 2

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

OTHER TIPS

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.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top