Rounding float in Ruby

后端 未结 9 1174
北恋
北恋 2020-12-12 13:33

I\'m having problems rounding. I have a float, which I want to round to the hundredth of a decimal. However, I can only use .round which basically turns it in

9条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-12 13:41

    If you just need to display it, I would use the number_with_precision helper. If you need it somewhere else I would use, as Steve Weet pointed, the round method

提交回复
热议问题