Parse a number as string
557876
public static Number parseNumber( String numberAsString )  throws InvalidSelectorException
    {
        if (numberAsString == null) return null;
        try
        {
            if (numberAsString.indexOf('.') != -1 || 
                numberAsString.indexOf('e') != -1 ||
                numberAsString.indexOf('E') != -1)
            {
                return new Double(numberAsString);
            }
            else
                return Long.valueOf(numberAsString);
        }
        catch (NumberFormatException e)
        {
            throw new InvalidSelectorException("Invalid numeric value : "+numberAsString);
        }
    }
648911
protected Number parseNumber(String text) {
        if (INTEGER_PATTERN.matcher(text).matches()) {
            return Integer.parseInt(text);
        }

        if (DOUBLE_PATTERN.matcher(text).matches()) {
            return Double.parseDouble(text);
        }

        if (FLOAT_PATTERN.matcher(text).matches()) {
            return Float.parseFloat(text);
        }

        return null;
    }
376298
protected Number parseFloat(String string) throws ParseException {
		try {
			return Double.valueOf(string);
		} catch (NumberFormatException e) {
			fail(FLOAT);
			return null;
		}
	}
344577
def parse_number(val, use_dateutilparser=False):
    
    if use_dateutilparser:
        funcs = [int, float, parse_list_from_string,
                 dateutil.parser.parse, str]
    else:
        funcs = [int, float, parse_list_from_string, str]
    if (val.strip().startswith("'") and val.strip().endswith("'")) or (val.strip().startswith('"') and val.strip().endswith('"')):
        return val[1:-1]
    for f in funcs:
        try:
            return f(val)
        # eat exception
        except (ValueError, UnicodeEncodeError, UnicodeDecodeError) as ve:
            pass
    raise ValueError('Cannot parse number:', val)
863022
def _try_parse_basic_number(self, data):
        

        # try int first
        try:
            return int(data)
        except ValueError:
            pass
        # try float next
        try:
            return float(data)
        except ValueError:
            pass
        # no luck, return data as it is
        return data
426687
def parsedate(data):
    """"""
    t = parsedate_tz(data)
    if isinstance(t, tuple):
        return t[:9]
    else:
        return t
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
1081605
def _parse_number_from_substring(smoothie_substring):
    '''
    
    '''
    try:
        return round(
            float(smoothie_substring.split(':')[1]),
            GCODE_ROUNDING_PRECISION
        )
    except (ValueError, IndexError, TypeError, AttributeError):
        log.exception('Unexpected argument to _parse_number_from_substring:')
        raise ParseError(
            'Unexpected argument to _parse_number_from_substring: {}'.format(
                smoothie_substring))
819645
def int_to_string(number, alphabet, padding=None):
    
    output = ""
    alpha_len = len(alphabet)
    while number:
        number, digit = divmod(number, alpha_len)
        output += alphabet[digit]
    if padding:
        remainder = max(padding - len(output), 0)
        output = output + alphabet[0] * remainder
    return output[::-1]
21743
def _num_to_string(self, number, pad_to_length=None):
        
        output = ""
        while number:
            number, digit = divmod(number, self._alpha_len)
            output += self._alphabet[digit]
        if pad_to_length:
            remainder = max(pad_to_length - len(output), 0)
            output = output + self._alphabet[0] * remainder
        return output
291049
def is_number(string):
    
    string = str(string)
    if string.isnumeric():
        return True
    try:
        float(string)
        return True
    except ValueError:
        return False
759682
function parsePrice(s) {
  if (typeof s === 'number') return s;
  s = str(s).replace(/[\s,$]/g,'');
  return s ? Number(s) : NaN;
}
154817
def string_to_int( s ):
  """"""
  result = 0
  for c in s:
    if not isinstance(c, int): c = ord( c )
    result = 256 * result + c
  return result
1228921
def from_string(cls, s):
        """"""
        for num, text in cls._STATUS2STR.items():
            if text == s:
                return cls(num)
        else:
            raise ValueError("Wrong string %s" % s)
509464
def parse_numtuple(s,intype,length=2,scale=1):
    ''''''
    if intype == int:
        numrx = intrx_s;
    elif intype == float:
        numrx = fltrx_s;
    else:
        raise NotImplementedError("Not implemented for type: {}".format(
            intype));
    if parse_utuple(s, numrx, length=length) is None:
        raise ValueError("{} is not a valid number tuple.".format(s));
    return [x*scale for x in evalt(s)];
548770
def _to_number(cls, string):
        """"""
        try:
            if float(string) - int(string) == 0:
                return int(string)
            return float(string)
        except ValueError:
            try:
                return float(string)
            except ValueError:
                return string
406564
function (str) {
            
            var typeOf = typeof str;
            if (typeOf === 'number')
                return str;
            
            else if (typeOf !== 'string')
                return Number.NaN;
            
            else if (_floatRegex.test(str))
                return parseFloat(str);
                
            else if (   str === 'Infinity'
                     || str === '+Infinity' )
                return Number.POSITIVE_INFINITY;
            
            else if (str === '-Infinity')
                return Number.NEGATIVE_INFINITY;
            
            else  // whether "NaN" or any other string
                return Number.NaN;
        }