float和double数据类型可以存储纬度和经度吗? [英] float and double datatype is good to store latitude and longitude?

查看:1493
本文介绍了float和double数据类型可以存储纬度和经度吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在服务器端存储纬度和经度(JAVA平台)。

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

要存储这些值,我在服务器端使用float和double数据类型。我开始知道float和double不是推荐的原始数据类型(建议不要以专业方式使用货币),因为float和double有舍入精度问题

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.

问题1:

将坐标与数据类型(浮点数或双精度数)进行比较将来会出现任何问题吗?

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

问题2:

使用大小数是好的吗?或者使用浮点数或双倍更安全?

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

推荐答案

这不是一个安全问题,只是一个精确的问题。
我不会考虑花车,但双打是我认为理想的。
你只需要看看你能从双精度中获得的最精确度,看看它是否符合常规的经度/纬度值。我认为它已经足够了。

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.

其他BigDecimal只是你问题的一个简单后门,如果你想要更高的精度就可以使用它

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

这篇关于float和double数据类型可以存储纬度和经度吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆