Puppet Function: validate_float

Defined in:
lib/puppet/parser/functions/validate_float.rb
Function type:
Ruby 3.x API

Overview

validate_float()N

Validates whether or not the passed argument is a float

Returns:

  • (N)

    N



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/puppet/parser/functions/validate_float.rb', line 2

newfunction(:validate_float, :doc => <<-EOS) do |args|

  if (args.size != 1)
  Validates whether or not the passed argument is a float

  @return [Nil]
  EOS
    raise(Puppet::ParseError, "is_float(): Wrong number of args "+
      "given #{args.size} for 1")
  end

  value = "#{args[0]}"

  if value != value.to_f.to_s.sub(/\.0$/,'')
    raise Puppet::ParseError, ("'#{args}' is not a float.")
  end
end