# DMS coordinates precision

I'm trying to convert Lat/Lon coordinate to decimal and vice-versa.

When I convert `16° 17′ 31″ S 48° 46′ 31″ W` to decimal I got `-48.775277777777774, -16.291944444444447` but I can see the original coordinate from OpenLayers is `-48.775058943087124, -16.291811459160023`.

My steps:

• Take coordinate from map (`-48.775058943087124, -16.291811459160023`).
• Convert to DMS using `hdms = ol.coordinate.toStringHDMS( coordinate )`. Got `16° 17′ 31″ S 48° 46′ 31″ W`.
• Convert DMS back to decimal using the function from link above. Result is `-48.775277777777774, -16.291944444444447`.

How can I achieve the correct precision?

In integer DSM coordinates the best precision is a second so `1/60/60` or 0.000277778.

So you need to truncate your results at 3 digits after the decimal so your results do agree.

Update

I went and looked at the code which seems as though you can specify the precision of the seconds variable through an option.

``````hdms = ol.coordinate.toStringHDMS( coordinate, 5 )
``````

should give a result like `16° 17′ 31.xxxxx″ S 48° 46′ 31.xxxxx″ W`

• I can't do this bro... I need to be precise. If I truncate a coordinate I spread the location where to find my point. If I say a point is at `-48.775058943087124, -16.291811459160023` then there it must to be. – Magno C Nov 14 '17 at 17:27
• then you need more precision on your seconds' values. – Ian Turton Nov 14 '17 at 17:28
• Well... following my example I found that `31 / ( 60 * 60 ) = 0,0086111111111111` plus `17 / 60 = 0,2833333333333333` I have `0,2919444444444444`. The precision is gone just as calculation begin... It must be `0.291811459160023`. – Magno C Nov 14 '17 at 17:33
• About your edit: BRILHANT! Worked! – Magno C Nov 14 '17 at 17:57
• When I doubt rtfs – Ian Turton Nov 14 '17 at 17:57