tkrajina / gpxpy

gpx-py is a python GPX parser. GPX (GPS eXchange Format) is an XML based file format for GPS tracks.
Apache License 2.0
1.02k stars 223 forks source link

Latitude/longitude parsing loses precision by converting to `float` #37

Closed micolous closed 8 years ago

micolous commented 10 years ago

It appears in https://github.com/tkrajina/gpxpy/blob/master/gpxpy/utils.py#L58, the to_numeric function uses the built-in float to convert a str to a numeric value.

As a result, the latitude and longitude loses precision, and the amount of precision lost is dependent on the Python implementation.

Instead, this should use decimal.Decimal, which has a fixed precision.

tkrajina commented 10 years ago

I'm aware of this. For my own usage this loss of precision is not a big deal but agree that for some use-cases this may be important.

Anyway, instead of changing the to_numeric function, I thinks it is better to change the parser in the gpx-1.1 since I rewrote the parser there and I plan to merge it to master. I think I'll use float() by default and decimal.Decimal only when the user needs it.