Double or decimal for latitude/longitude values in C#

KRTac picture KRTac · Jan 21, 2015 · Viewed 41.6k times · Source

What is the best data type to use when storing geopositional data in C#? I would use decimal for it's exactness, but operations on decimal floating point numbers are slower then binary floating point numbers (double).

I read that most of the time you won't need any more then 6 or 7 digits of precision for latitude or longitude. Does the inexactness of doubles even matter then or can it be ignored?

Answer

Wernfried Domscheit picture Wernfried Domscheit · Jan 22, 2015

Go for double, there are several reasons.

  • Trigonometric functions are available only for double
  • Precision of double (range of 100 nanometers) is far beyond anything you'll ever require for Lat/Lon values
  • GeoCoordinate Class and third-Party modules (e.g. DotSpatial) also use double for coordinates