Ruby on rails 3 - Show decimals
Probably one of the simpler questions but I haven't found a 开发者_JAVA百科solution for it. I want to show 2 decimals after making an equation of numbers coming from a database.
This is the code I have.
(((@best.price * @amount) + @best.retailer.profile.shippingCost)/(@best.productSize.productSize * @amount))
number_with_precision is your friend:
number = (((@best.price * @amount) + @best.retailer.profile.shippingCost)/(@best.productSize.productSize * @amount))
Then in your view:
number_with_precision(number, :precision => 2)
精彩评论