Convert a string of a calculation energy, e.g. '-1.2345 eV' to a float.

    Args:
        string (str): The string to convert.
  
    Return
        (float)
1277
def energy_string_to_float( string ):
    
    energy_re = re.compile( "(-?\d+\.\d+)" )
    return float( energy_re.match( string ).group(0) )
1108145
def p_str(p):
    
    if is_number(p[2]):  # A constant is converted to string directly
        p[0] = symbols.STRING(str(p[2].value), p.lineno(1))
    else:
        p[0] = make_builtin(p.lineno(1), 'STR',
                            make_typecast(TYPE.float_, p[2], p.lineno(1)),
                            type_=TYPE.string)
1095713
def numberize(string):
    ''''''
    if not isinstance(string,basestring):
        return string
    just_int = r'^\s*[-+]?\d+\s*$'
    just_float = r'^\s*[-+]?\d+\.(\d+)?\s*$'
    if re.match(just_int,string):
        return int(string)
    if re.match(just_float,string):
        return float(string)
    return string
483209
def _parse(string):
    
    if not isinstance(string, str):
        raise ValueError('Config value "{0}" expected to be string.'
                         .format(string))
    if string in ['true', 'True']:
        return True
    elif string in ['false', 'False']:
        return False
    elif string in ['float64', 'float32', 'float16',
                    'int64', 'int32', 'int16']:
        return getattr(np, string)
    else:
        try:
            return int(string)
        except ValueError:
            pass
        try:
            return float(string)
        except ValueError:
            return string
702392
def _isnumber(string):
    
    if not _isconvertible(float, string):
        return False
    elif isinstance(string, (_text_type, _binary_type)) and (
            math.isinf(float(string)) or math.isnan(float(string))):
        return string.lower() in ['inf', '-inf', 'nan']
    return True
558798
def format_value(value):
    
    value = decimal.Decimal(str(value))
    if int(value) == value:
        return int(value)

    # On Python 3, an explicit cast to float is required
    return float(round(value, 1))
943839
function(string) {
		var result = String(string);
		switch (result) {
			case "null":
				result = null;
				break;
			case "true":
			case "false":
				result = (result === "true");
				break;
			default:
				if (String(parseInt(result, 10)) === result) {
					result = parseInt(result, 10);
				} else if (String(parseFloat(result)) === result) {
					result = parseFloat(result);
				}
				break;
		}
		return result;
	}
1326630
def form(value):
    
    if isinstance(value, FLOAT + INT):
        if value <= 0:
            return str(value)
        elif value < .001:
            return '%.3E' % value
        elif value < 10 and isinstance(value, FLOAT):
            return '%.5f' % value
        elif value > 1000:
            return '{:,d}'.format(int(round(value)))
        elif numpy.isnan(value):
            return 'NaN'
        else:  # in the range 10-1000
            return str(int(value))
    elif isinstance(value, bytes):
        return decode(value)
    elif isinstance(value, str):
        return value
    elif isinstance(value, numpy.object_):
        return str(value)
    elif hasattr(value, '__len__') and len(value) > 1:
        return ' '.join(map(form, value))
    return str(value)
828825
public static float stringToFloat(String string) {
        string = string.trim();
        if (Checker.isDecimal(string)) {
            return Float.parseFloat(string);
        }
        return -1;
    }
174468
def get_float(self, input_string):
        

        if input_string == '--training_fraction':

            # was the flag set?
            try:
                index = self.args.index(input_string) + 1
            except ValueError:
                # it wasn't, it's optional, so return the appropriate default
                return None

            # the flag was set, so check if a value was set, otherwise exit
            try:
                if self.args[index] in self.flags:
                    print("\n {flag} was set but a value was not specified".format(flag=input_string))
                    print_short_help()
                    sys.exit(1)
            except IndexError:
                print("\n {flag} was set but a value was not specified".format(flag=input_string))
                print_short_help()
                sys.exit(1)

            # a value was set, so check if its the correct type
            try:
                value = float(self.args[index])
            except ValueError:
                print("\n {flag} must be a float less than or equal to 1, e.g. 0.4".format(flag=input_string))
                print_short_help()
                sys.exit(1)
            if value > 1.0 or value < 0:
                print("\n {flag} must be a float less than or equal to 1, e.g. 0.4".format(flag=input_string))
                print_short_help()
                sys.exit(1)

            # everything checks out, so return the appropriate value
            return value
1126392
def _float(self, string):
        
        string = self._denoise(string)
        exp_match = re.match(r'^[-.\d]+x10-(\d)$', string)
        if exp_match:
            exp = int(exp_match.groups()[0])
            fac = 10 ** -exp
            string = string.replace('x10-{}'.format(exp), '')
        else:
            fac = 1

        return fac * float(string)
1176246
def from_string(self, value):
        """"""
        if not isinstance(value, basestring):
            raise ValueError('expected string value: ' + str(type(value)))
        self.test_value(value)
        return value
100045
def __float(value):
    ''''''
    valid, _value = False, value
    try:
        _value = float(value)
        valid = True
    except ValueError:
        pass
    return (valid, _value, 'float')
130258
def _string_to_int(self, string):
        
        number = 0
        for char in string[::-1]:
            number = number * self._alpha_len + self._alphabet.index(char)
        return number
908058
def str_to_dt(val):
    

    if isinstance(val, dt):
        return val

    try:
        if val.isdigit():
            return dt.utcfromtimestamp(float(val))
        else:
            return dt.strptime(val, '%Y-%m-%dT%H:%M:%S.%f')
    except (AttributeError, TypeError):
        raise ValueError
773417
def __to_float(val, digits):
    """"""
    try:
        return round(float(val), digits)
    except (ValueError, TypeError):
        return float(0)
1261991
def from_string(cls, s):
        
        # Extract num and unit string.
        s = s.strip()
        for i, char in enumerate(s):
            if char.isalpha() or char.isspace():
                break
        else:
            raise Exception("Unit is missing in string %s" % s)
        num, unit = float(s[:i]), s[i:]

        # Find unit type (set it to None if it cannot be detected)
        for unit_type, d in BASE_UNITS.items():
            if unit in d:
                break
        else:
            unit_type = None

        return cls(num, unit, unit_type=unit_type)