开发者

What's the best way to round a Ruby BigDecimal number to the nearest 0.05?

Ruby's BigDecimal #round method rounds numbers off to the nearest integer (and returns it as a fixnum frustratingly). Is there a built in method to allo开发者_开发百科w rounding to the nearest 0.05? I can't find one.

The best I have managed is

def round05(number)
  (BigDecimal.new (number * 20).round.to_s) /20
end
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜