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
精彩评论