Sha256: 428d76f6fa814e17b59768d9e2c6fe7de706e1b2ca85156792acb1e67bb3a62d

Contents?: true

Size: 492 Bytes

Versions: 23

Compression:

Stored size: 492 Bytes

Contents

class Float
  if instance_method(:round).arity.zero?
    def round_with_digits(ndigits=0)
      ndigits = Backports::coerce_to_int(ndigits)
      case
      when ndigits.zero?
        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? ? self : prod.round.fdiv(p)
      end
    end
    Backports.alias_method_chain self, :round, :digits
  end
end

Version data entries

23 entries across 23 versions & 2 rubygems

Version Path
backports-3.0.3 lib/backports/1.9.1/float.rb
backports-3.0.2 lib/backports/1.9.1/float.rb
backports-3.0.1 lib/backports/1.9.1/float.rb
backports-3.0.0 lib/backports/1.9.1/float.rb
backports-2.8.2 lib/backports/1.9.1/float.rb
backports-2.8.1 lib/backports/1.9.1/float.rb
backports-2.8.0 lib/backports/1.9.1/float.rb
backports-2.7.1 lib/backports/1.9.1/float.rb
backports-2.7.0 lib/backports/1.9.1/float.rb
backports-2.6.7 lib/backports/1.9.1/float.rb
backports-2.6.6 lib/backports/1.9.1/float.rb
backports-2.6.5 lib/backports/1.9.1/float.rb
fragrant-0.0.5 vendor/bundle/ruby/1.9.1/gems/backports-2.6.4/lib/backports/1.9.1/float.rb
backports-2.6.4 lib/backports/1.9.1/float.rb
backports-2.6.3 lib/backports/1.9.1/float.rb
backports-2.6.2 lib/backports/1.9.1/float.rb
backports-2.6.1 lib/backports/1.9.1/float.rb
backports-2.6.0 lib/backports/1.9.1/float.rb
backports-2.5.3 lib/backports/1.9.1/float.rb
backports-2.5.2 lib/backports/1.9.1/float.rb