Sha256: 5c317ec4274189926d611d80073780e705dc85f4f570256fbe011acad518ba5a
Contents?: true
Size: 541 Bytes
Versions: 26
Compression:
Stored size: 541 Bytes
Contents
if Float.instance_method(:round).arity.zero? require 'backports/tools' class Float def round_with_digits(ndigits=0) ndigits = Backports::coerce_to_int(ndigits) case when ndigits == 0 round_without_digits when ndigits < 0 p = 10 ** -ndigits p > abs ? 0 : (self / p).round * p else p = 10 ** ndigits prod = self * p prod.infinite? || prod.nan? ? self : prod.round.to_f / p end end Backports.alias_method_chain self, :round, :digits end end
Version data entries
26 entries across 26 versions & 2 rubygems