When storing latitudes/longitudes which are typically of the format: 44.087585 (i.e. max 2 numbers before the dot and 6dp) do I need to bother with bigdecimals?
-
2Irrelevant for the question, but longitude values range from -180 to 180, so that's 3 numbers before the dot. And a potential minus sign :P – Tom Ladek Jun 19 '17 at 10:27
6 Answers
Using double
has enough precision for accurate lat/lon down to inches for 6-7 decimal places. In aviation, if decimal degrees are used, they typically go to at least 7 decimal places. In our NASA simulations, lat/lon data are doubles
while all other attitude and altitude are floats. In other words, the 6th decimal place for altitude isn't significant while the 6th decimal place for lat/lon is for sub-foot accuracy. You should not use float
for lat/lon if you need precision down to sub-feet.
You can play around in Google Earth to see what accuracy you get by placing markers and manipulating the last decimal digit.

- 17,291
- 7
- 48
- 81

- 3,339
- 2
- 20
- 26
-
11+1 for the good explanation of the decimal point accuracy with respect to logitudes/latitudes. – CoolBeans Jul 20 '11 at 18:11
double
should be fine for latitudes/longitudes. BigDecimal
becomes more important once you start manipulating currency or need to have more control over precision.
-
12Downvoter: Why the down vote? Feel free to leave a comment - it will make you look reasonable. – CoolBeans Jul 20 '11 at 03:36
A double
has enough precision for storing that. However, when displaying to users, use a format string like %.6f
so that you don't print garbage digits out.

- 219,335
- 46
- 382
- 435
The worst accuracy of storing as double is about 3 nm.
If you'd like to calculate it in Java:
Math.ulp((double) 180) * 60 * 1852
3.1582203519064933E-9
As a bonus; the worst accuracy you get from storing in floats is 1.7 meters.

- 799
- 1
- 6
- 13
-
1I just realized that I also need to make pythagoras with the greatest error in the other direction too. So a little bit worse. :) – Gussoh Mar 19 '14 at 14:52
If you're concerned about precision, you should probably go with BigDecimal
for lots of reasons covered in this post. That said, double
or float
should be just fine to store what you need in terms of being able to satisfy the range of values that you need.
At just six decimal places of precision I don't think double
or float
will trip you up, but if you start aggregating the values in any way, the minor imprecisions can start to add up.

- 1
- 1

- 55,313
- 14
- 116
- 115
if you want to control nano-robots in their nano-travels using nano-GPS - go for BigDecimal. otherwise - float/double is enough.

- 8,006
- 1
- 28
- 33