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

别来无恙 提交于 2019-12-20 19:43:25

问题


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?


回答1:


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




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/20657172/float-and-double-datatype-is-good-to-store-latitude-and-longitude

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!