title: Working with decimals in Ruby on Rails 3
body: <p>I'm trying to calculate the average net price of a product. I have, in my Product model :total_sold and :total_net_revenue. Doing straight division in the method seems to always result in 0. I resorted to using BigDecimal as I figured that was the problem ... but with my latest iteration of the code below, I'm still getting zero when the answer comes out to a decimal.</p>
  
  <pre><code>def avg_price
    BigDecimal(total_sold.to_s) / (BigDecimal(total_net_revenue.to_s) / 100)
  end  
  </code></pre>
  
  <p>Net revenue is in cents, which is why I divide by 100. Can someone point out what I'm doing wrong or should do?</p>