title: Float vs Decimal in ActiveRecord
body: <p>Sometimes, Activerecord data types confuse me. Err, often. One of my eternal questions is, for a given case,</p>
  
  <blockquote>
    <p>Should I use <code>:decimal</code> or <code>:float</code>?</p>
  </blockquote>
  
  <p>I've often come across this link, <em><a href="http://railsforum.com/viewtopic.php?id=39211">ActiveRecord: :decimal vs :float?</a></em>, but the answers aren't quite clear enough for me to be certain:</p>
  
  <blockquote>
    <p>I've seen many threads where people recommend flat out to never use
    float and always use decimal. I've also seen suggestions by some
    people to use float for scientific applications only.</p>
  </blockquote>
  
  <p>Here are some example cases:</p>
  
  <ul>
  <li>Geolocation/latitude/longitude: <code>-45.756688</code>, <code>120.5777777</code>, ...</li>
  <li>Ratio/percentage: <code>0.9</code>, <code>1.25</code>, <code>1.333</code>, <code>1.4143</code>, ...</li>
  </ul>
  
  <p>I have used <code>:decimal</code> in the past, but I found dealing with <code>BigDecimal</code> objects in Ruby was unnecessarily awkward as compared to a float. I also know I can use <code>:integer</code> to represent money/cents, for example, but it doesn't quite fit for other cases, for example when quantities in which precision could change over time.</p>
  
  <ul>
  <li>What are the advantages/disadvantages of using each?</li>
  <li>What would be some good rules of thumb to know which type to use?</li>
  </ul>