Rails 3 Float or decimal for GPS coordinates

前端 未结 4 1175
走了就别回头了
走了就别回头了 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:49

    If you want 100% accuracy with your decimals, then multiply by 10**n(where n is your desired precision), and store as integer.

    Float objects represent inexact real numbers using the native architecture's double-precision floating point representation.

    See:

    http://www.ruby-doc.org/core-1.9.3/Float.html
    

提交回复
热议问题