Sha256: 7a943aa6e031538fe4dd1cc8f72b97d516b01294b340b0a20db02651c0f13063

Contents?: true

Size: 812 Bytes

Versions: 26

Compression:

Stored size: 812 Bytes

Contents

#--
# Credit goes to George Moschovitis
#++

class Numeric

  # Returns the multiple ceil of a number.
  def ceil_multiple(multiple)
    # gmosx: to_f is needed!
    # gmosx: IS THERE a more optimized way to do this?
    return ((self.to_f/multiple).ceil*multiple)
  end

end


#  _____         _
# |_   _|__  ___| |_
#   | |/ _ \/ __| __|
#   | |  __/\__ \ |_
#   |_|\___||___/\__|
#
=begin test

  require 'test/unit'

  class TCNumeric < Test::Unit::TestCase

    def test_ceil_multiple
      assert_equal( 12.3, 12.3.ceil_multiple(0.1) )
      assert_equal( 12.4, 12.31.ceil_multiple(0.1) )
      assert_equal( 13, 12.3.ceil_multiple(1) )
      assert_equal( 13, 12.31.ceil_multiple(1) )
      assert_equal( 20, 12.3.ceil_multiple(10) )
      assert_equal( 20, 12.31.ceil_multiple(10) )
    end

  end

=end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
facets-1.0.0 lib/facet/numeric/ceil_multiple.rb
facets-0.9.0 lib/nano/numeric/ceil_multiple.rb
facets-1.0.3 packages/core/lib/facet/numeric/ceil_multiple.rb
facets-1.2.1 lib/facets/core/numeric/ceil_multiple.rb
facets-1.2.0 lib/facets/core/numeric/ceil_multiple.rb
facets-1.3.0 lib/facets/core/numeric/ceil_multiple.rb
facets-1.1.0 lib/facet/numeric/ceil_multiple.rb
facets-1.3.1 lib/facets/core/numeric/ceil_multiple.rb
facets-1.3.3 lib/facets/core/numeric/ceil_multiple.rb
facets-1.3.2 lib/facets/core/numeric/ceil_multiple.rb
facets-1.4.0 lib/facets/core/numeric/ceil_multiple.rb
facets-1.4.1 lib/facets/core/numeric/ceil_multiple.rb
facets-1.4.2 lib/facets/core/numeric/ceil_multiple.rb
facets-1.4.3 lib/facets/core/numeric/ceil_multiple.rb
facets-1.4.4 lib/facets/core/numeric/ceil_multiple.rb
facets-1.4.5 lib/facets/core/numeric/ceil_multiple.rb
facets-1.7.0 lib/facets/core/numeric/ceil_multiple.rb
facets-1.7.30 lib/facets/core/numeric/ceil_multiple.rb
facets-1.7.38 lib/facets/core/numeric/ceil_multiple.rb
facets-1.7.46 lib/facets/core/numeric/ceil_multiple.rb