Philip
Philip

Reputation: 7166

Ruby on rails 3 - Show decimals

Probably one of the simpler questions but I haven't found a 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))

Upvotes: 0

Views: 734

Answers (1)

Matt
Matt

Reputation: 17639

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)

Upvotes: 4

Related Questions