Rails 3 Float or decimal for GPS coordinates

decimal-point, floating-point, ruby-on-rails

Solution

If you want more accurate GPS coordinates, then yes decimals are the way to go. You can create them with a migration like:

create_table "models" do |t|
  t.decimal  "latitude", :precision => 15, :scale => 10, :default => 0.0
  t.decimal  "longitude", :precision => 15, :scale => 10, :default => 0.0
end

The reason people use floats is that they are usually precise enough for most use cases and use less space to store.

Problem

I need to store GPS coordinates in a database. I've heard that floats are less accurate than decimals. Is that true? If so, what reason is there to ever use floats?

Original source