I'm making a JSON API for my iOS app, and (even though I format it on the client) I would like to store my lat/long data in the format it will be seen on the client.
My current solution
class Location < ActiveRecord::Base
before_save :format_coordinate_precision
def format_coordinate_precision
lati = "%.8f" % self.latitude
self.latitude = lati.to_f
end
Gives me a guaranteed 8 digits of precision, but omits trailing zeros. Plus this doesn't look like the most production quality approach to this. There's the ActionView::Helpers::NumberHelper number_with_precision
but that seems to be for use in .erb view files.