四捨五入
class Float def round2(n) list = to_s.split("") point = list.index(".") + n + 1 ret = list[0,point].join.to_f ret += 0.1 ** n if list[point].to_i >= 5 ret end end puts 0.984.round2(2) #=> 0.98 puts 0.985.round2(2) #=> 0.99 puts 0.995.round2(2) #=> 1.0 puts 9.995.round2(2) #=> 10.0 puts 0.984.round2(3) #=> 0.984 puts 0.984.round2(5) #=> 0.984