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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

thtas created an issue. See original summary.

thtas’s picture

Status: Needs work » Needs review
FileSize
3.32 KB

See patch with some unit tests added which might clarify things a bit.

thtas’s picture

FileSize
3.32 KB

.patch extension

thtas’s picture

FileSize
3.32 KB

better patch