Sha256: b886ab20ee0688526a746b1b4b33333d899c60e159df355c92566dd63725dd2d

Contents?: true

Size: 518 Bytes

Versions: 20

Compression:

Stored size: 518 Bytes

Contents

# frozen_string_literal: true
# Returns an `Integer` value rounded to the nearest value.
# Takes a single `Numeric` value as an argument.
#
# @example 'rounding a value'
#
# ```puppet
# notice(round(2.9)) # would notice 3
# notice(round(2.1)) # would notice 2
# notice(round(-2.9)) # would notice -3
# ```
#
Puppet::Functions.create_function(:round) do
  dispatch :on_numeric do
    param 'Numeric', :val
  end

  def on_numeric(x)
    if x > 0
      Integer(x + 0.5)
    else
      Integer(x - 0.5)
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
puppet-8.3.0 lib/puppet/functions/round.rb
puppet-8.3.0-x86-mingw32 lib/puppet/functions/round.rb
puppet-8.3.0-x64-mingw32 lib/puppet/functions/round.rb
puppet-8.3.0-universal-darwin lib/puppet/functions/round.rb
puppet-8.3.1 lib/puppet/functions/round.rb
puppet-8.3.1-x86-mingw32 lib/puppet/functions/round.rb
puppet-8.3.1-x64-mingw32 lib/puppet/functions/round.rb
puppet-8.3.1-universal-darwin lib/puppet/functions/round.rb
puppet-8.2.0 lib/puppet/functions/round.rb
puppet-8.2.0-x86-mingw32 lib/puppet/functions/round.rb
puppet-8.2.0-x64-mingw32 lib/puppet/functions/round.rb
puppet-8.2.0-universal-darwin lib/puppet/functions/round.rb
puppet-8.1.0 lib/puppet/functions/round.rb
puppet-8.1.0-x86-mingw32 lib/puppet/functions/round.rb
puppet-8.1.0-x64-mingw32 lib/puppet/functions/round.rb
puppet-8.1.0-universal-darwin lib/puppet/functions/round.rb
puppet-8.0.1 lib/puppet/functions/round.rb
puppet-8.0.1-x86-mingw32 lib/puppet/functions/round.rb
puppet-8.0.1-x64-mingw32 lib/puppet/functions/round.rb
puppet-8.0.1-universal-darwin lib/puppet/functions/round.rb