Sha256: 86e25cfa744efd47564a1e0a6ff59b542d51770ee27b64ca9612ed6ff40fc0e9

Contents?: true

Size: 985 Bytes

Versions: 6

Compression:

Stored size: 985 Bytes

Contents

module Polyfill
  module V2_4
    module Float
      def ceil(ndigits = 0)
        ndigits = ndigits.to_int
        return super() if ndigits == 0

        if ndigits > 0
          place = 10**ndigits
          (self * place).ceil / place.to_f
        else
          place = 10**-ndigits
          (self / place).ceil * place
        end
      end

      def floor(ndigits = 0)
        ndigits = ndigits.to_int
        return super() if ndigits == 0

        if ndigits > 0
          place = 10**ndigits
          (self * place).floor / place.to_f
        else
          place = 10**-ndigits
          (self / place).floor * place
        end
      end

      def truncate(ndigits = 0)
        ndigits = ndigits.to_int
        return super() if ndigits == 0

        if ndigits > 0
          place = 10**ndigits
          (self * place).truncate / place.to_f
        else
          place = 10**-ndigits
          (self / place).truncate * place
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
polyfill-1.0.1 lib/polyfill/v2_4/float.rb
polyfill-1.0.0 lib/polyfill/v2_4/float.rb
polyfill-0.10.0 lib/polyfill/v2_4/float.rb
polyfill-0.9.0 lib/polyfill/v2_4/float.rb
polyfill-0.8.0 lib/polyfill/v2_4/float.rb
polyfill-0.7.0 lib/polyfill/v2_4/float.rb