开发者

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)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜