When formatting latitudes and longitudes using Decimal degrees, the rounding produces some odd output when the data stores recurring values.
For example, the location of 1 degree and 20 minutes will be stored as 1.333333333333
But when it's converted back to to degrees minutes seconds for display, it will show as 1 degree 19 minutes 60 seconds (which isn't really a nice way write a coordinate, much like it's not correct to write 11:60 instead of 12:00)
Steps to reproduce.
1. Add a geofield to a node
2. Set the output format for the field to "Decimal degrees"
3. Create a node and set the geofield values to latitude 1.333333333333 and longitude 179.999999999999. (using 12 decimal places because that is the database precision)
Expected:
Latitude: 1° 20' 0" N
Longitude: 180° 0' 0" E
Actual:
Latitude: 1° 19' 60" N
Longitude: 180° 0' 0" E
Note:
The 179.999999999999 actually gets rounded to 180 when it's stored in the DB.
if we use one less decimal precision on the input, we actually see 179° 59' 60" E on the output.
Comment | File | Size | Author |
---|---|---|---|
#4 | better-rounding-on-DMS-formatter-2846487-4.patch | 3.32 KB | thtas |
Comments
Comment #2
thtas CreditAttribution: thtas commentedSee patch with some unit tests added which might clarify things a bit.
Comment #3
thtas CreditAttribution: thtas commented.patch extension
Comment #4
thtas CreditAttribution: thtas commentedbetter patch