Method: Rsmart::ETL.parse_float

Defined in:
lib/rsmart_toolbox/etl.rb

.parse_float(str, opt = {}) ⇒ Float?

Note:

Note the behavioral difference versus #to_f.

Parse a Float from a String.

Examples:

Unlike #to_f, nil or empty inputs will return nil by default

nil == parse_float(nil) && nil == parse_float('') && 0.0 != parse_float(nil)

Parameters:

  • str (String)

    the String to be parsed.

  • opt (Hash) (defaults to: {})

    options Hash will be passed through to #parse_string.

Returns:

  • (Float, nil)

    the parsed Float. nil or empty inputs will return nil by default.

See Also:



256
257
258
259
260
261
262
263
# File 'lib/rsmart_toolbox/etl.rb', line 256

def self.parse_float(str, opt={})
  s = parse_string str, opt
  if s.empty?
    return nil;
  else
    return s.to_f
  end
end