Mercurial > repos > other > Puppet
view modules/stdlib/lib/puppet/parser/functions/round.rb @ 275:d9352a684e62
Mass update of modules to remove deprecation warnings
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 26 Jan 2020 11:36:07 +0000 |
parents | c42fb28cff86 |
children |
line wrap: on
line source
# # round.rb # module Puppet::Parser::Functions newfunction(:round, :type => :rvalue, :doc => <<-DOC @summary Rounds a number to the nearest integer @return the rounded value as integer @example ```round(2.9)``` returns ```3``` ```round(2.4)``` returns ```2``` > *Note:* from Puppet 6.0.0, the compatible function with the same name in Puppet core will be used instead of this function. DOC ) do |args| raise Puppet::ParseError, "round(): Wrong number of arguments given #{args.size} for 1" if args.size != 1 raise Puppet::ParseError, "round(): Expected a Numeric, got #{args[0].class}" unless args[0].is_a? Numeric value = args[0] if value >= 0 Integer(value + 0.5) else Integer(value - 0.5) end end end