From: Tom Hughes Date: Sun, 7 Jul 2024 13:44:45 +0000 (+0100) Subject: Use bigdecimal to avoid scientfic notation in DMS decoding X-Git-Tag: live~381^2~1 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/29dba7318a6c962da05751da42928d4096a73087?ds=inline;hp=--cc Use bigdecimal to avoid scientfic notation in DMS decoding --- 29dba7318a6c962da05751da42928d4096a73087 diff --git a/app/controllers/geocoder_controller.rb b/app/controllers/geocoder_controller.rb index 0dabc5a62..312762216 100644 --- a/app/controllers/geocoder_controller.rb +++ b/app/controllers/geocoder_controller.rb @@ -226,18 +226,18 @@ class GeocoderController < ApplicationController def to_decdeg(captures) ns = captures.fetch("ns").casecmp("s").zero? ? -1 : 1 - nsd = captures.fetch("nsd", "0").to_f - nsm = captures.fetch("nsm", "0").to_f - nss = captures.fetch("nss", "0").to_f + nsd = BigDecimal(captures.fetch("nsd", "0")) + nsm = BigDecimal(captures.fetch("nsm", "0")) + nss = BigDecimal(captures.fetch("nss", "0")) ew = captures.fetch("ew").casecmp("w").zero? ? -1 : 1 - ewd = captures.fetch("ewd", "0").to_f - ewm = captures.fetch("ewm", "0").to_f - ews = captures.fetch("ews", "0").to_f + ewd = BigDecimal(captures.fetch("ewd", "0")) + ewm = BigDecimal(captures.fetch("ewm", "0")) + ews = BigDecimal(captures.fetch("ews", "0")) lat = ns * (nsd + (nsm / 60) + (nss / 3600)) lon = ew * (ewd + (ewm / 60) + (ews / 3600)) - { :lat => lat, :lon => lon } + { :lat => lat.round(6).to_s("F"), :lon => lon.round(6).to_s("F") } end end