3

I want -122d 54m 8.41s W (DMS) to be converted as decimal (DD). I tried two different available online converters to do the calculation. Surprisingly outputs are different. It looks like they match up to 7th decimal places.

-122.902336120571
-122.90233611

Out of curiosity, I used open-source dms-conversion JavaScript library that handles conversion to test what value would be printed out. It came out as:

-122.90233611111111

Only common ground from this observation I can find is up to 7th decimal places matches. I am new to this subject area. I am not sure which decimal value I have to trust if I want it to be converted back as original DMS value.

I wonder each on-line converter and external JS library I tried out has different logic when it comes to truncate seconds?

If I need to implement conversion programmatically either using an external library or math formula available on-line such as this: Converting latitude and longitude to decimal values, how far I have to trust in decimal places for DD value?

Taras
  • 32,823
  • 4
  • 66
  • 137
DaeYoung
  • 131
  • 4

2 Answers2

3

Obligatory XKCD reference:

enter image description here

More detailed answer

Ian Turton
  • 81,417
  • 6
  • 84
  • 185
0

In javascript you only have the data type float available. There isn't a true decimal representation of all numbers to the right of the decimal point. There are some javascript math libraries that will convert to string and back (to decimal) to get as close to "true" as you require for significant digits. It comes down to doing division with binary numbers. I won't list any libraries here because they change. I hope this will help you find your answer.

Beau
  • 1