Rails 3 Float or decimal for GPS coordinates

前端 未结 4 1150
走了就别回头了
走了就别回头了 2020-12-31 09:00

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?

4条回答
  •  傲寒
    傲寒 (楼主)
    2020-12-31 09:48

    As you can see in Paul's answer, it depends on your use-case.
    A float provides a precision of roughly 6 decimal digits.
    ±11 cm is quite acceptable for, say, an address. and if you're displaying addresses it's unlikely that you are going to do any arithmetical operations that will compound rounding errors.

提交回复
热议问题