Double or decimal for latitude/longitude values in C#

前端 未结 4 1568
臣服心动
臣服心动 2020-12-24 04:02

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

4条回答
  •  抹茶落季
    2020-12-24 04:50

    A double has up to 15 decimal digits of precision. So, lets assume three of those digits are going to be on the left of the decimal point for lat/long values (max of 180deg). This leaves 12 digits of precision on the right. Since a degree of lat/long is ~111km, 5 of those 12 digits would give us precision to the meter. 3 more digits would give us precision to the millimeter. The remaining 4 digits would get us precision to around 100 nanometers. Since double will win from the perspective of performance and memory, I see no reason to even consider using decimal.

提交回复
热议问题