Sha256: 45bc1e6bf85a6b7d75f70df7464c57b11ba0fdf6336957a46cdba1d50f22c663

Contents?: true

Size: 519 Bytes

Versions: 32

Compression:

Stored size: 519 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

32 entries across 32 versions & 1 rubygems

Version Path
puppet-8.10.0 lib/puppet/functions/round.rb
puppet-8.10.0-x86-mingw32 lib/puppet/functions/round.rb
puppet-8.10.0-x64-mingw32 lib/puppet/functions/round.rb
puppet-8.10.0-universal-darwin lib/puppet/functions/round.rb
puppet-8.9.0 lib/puppet/functions/round.rb
puppet-8.9.0-x86-mingw32 lib/puppet/functions/round.rb
puppet-8.9.0-x64-mingw32 lib/puppet/functions/round.rb
puppet-8.9.0-universal-darwin lib/puppet/functions/round.rb
puppet-8.8.1 lib/puppet/functions/round.rb
puppet-8.8.1-x86-mingw32 lib/puppet/functions/round.rb
puppet-8.8.1-x64-mingw32 lib/puppet/functions/round.rb
puppet-8.8.1-universal-darwin lib/puppet/functions/round.rb
puppet-8.7.0 lib/puppet/functions/round.rb
puppet-8.7.0-x86-mingw32 lib/puppet/functions/round.rb
puppet-8.7.0-x64-mingw32 lib/puppet/functions/round.rb
puppet-8.7.0-universal-darwin lib/puppet/functions/round.rb
puppet-8.6.0 lib/puppet/functions/round.rb
puppet-8.6.0-x86-mingw32 lib/puppet/functions/round.rb
puppet-8.6.0-x64-mingw32 lib/puppet/functions/round.rb
puppet-8.6.0-universal-darwin lib/puppet/functions/round.rb