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.round…
引用をストックしました
引用するにはまずログインしてください
引用をストックできませんでした。再度お試しください
限定公開記事のため引用できません。