Parses a string with a locale and returns the corresponding number

@throws ParseException if number cannot be parsed
979648
public static double parseNumber(String number, Locale locale) throws ParseException {
    if ("".equals(number)) {
      return Double.NaN;
    }
    return NumberFormat.getNumberInstance(locale).parse(number).doubleValue();
  }
736177
public int parseIntegerString(String numberString) {
        StringReader sr = new StringReader(numberString);
        StreamTokenizer st = new StreamTokenizer(sr);
        st.parseNumbers();
        int tokenType;
        int returnValue = 0;

        try {
            if ((tokenType = st.nextToken()) != StreamTokenizer.TT_EOF) {
                if (tokenType == StreamTokenizer.TT_NUMBER) {
                    returnValue = (int) st.nval;
                }
            }
        }
        catch (IOException e) {
            Log.e(TAG, "Error: parseIntegerString - " + e);
        }
        return returnValue;
    }
395867
private static int parseAreaCode(String areaCode) {

    String normalized = areaCode;
    if (normalized.startsWith("(0)")) {
      normalized = normalized.substring(3);
    } else if (normalized.startsWith("(1)")) {
      normalized = normalized.substring(3);
    } else if (normalized.startsWith("0")) {
      normalized = normalized.substring(1);
    }
    if (normalized.startsWith("0")) {
      throw new IllegalArgumentException(areaCode);
    }
    try {
      int ac = Integer.parseInt(normalized);
      return ac;
    } catch (NumberFormatException e) {
      throw new IllegalArgumentException(areaCode, e);
    }
  }
1305919
public void parse(String string) {
    if (string == null) {
      throw new NullPointerException("string is null");
    }
    int bufferSize = Math.max(MIN_BUFFER_SIZE, Math.min(DEFAULT_BUFFER_SIZE, string.length()));
    try {
      parse(new StringReader(string), bufferSize);
    } catch (IOException exception) {
      // StringReader does not throw IOException
      throw new RuntimeException(exception);
    }
  }
1109726
function parseNumber (inp) {
    var res = "";
    if (inp.takeAPeek("-")) res += "-";
  
    var match = parseInteger(inp);
    if (match) res += match;
  
    match = parseFraction(inp);
    if (match) res += match;
  
    if (res && res !== "-") {
      match = parseExponent(inp);
      if (match) res += match;
    }
  
    if (res === "-") syntaxError(inp, "Expected number");
    return res || null;
  }
74185
public static Number toNumber(String string) {
    BigDecimal value = new BigDecimal(string);
    try {
      long l = value.longValueExact();
      int i = (int) l;
      if ((long) i == l) {
        return i;
      } else {
        return l;
      }
    } catch (ArithmeticException e) {
      double d = value.doubleValue();
      if (BigDecimal.valueOf(d).equals(value)) {
        float f = (float) d;
        if ((double) f == d) {
          return (float) d;
        } else {
          return d;
        }
      } else {
        return null;
      }
    }
  }
456995
@Override
    public double valueOf(String s) throws ParseException {
        Integer i = map.get(s);
        if (i == null) {
            if (open) {
                i = values.size();
                map.put(s, i);
                values.add(s);
            } else {
                throw new ParseException("Invalid string value: " + s, 0);
            }
        }
        
        return i;
    }
46383
Token parseAtom() throws ParseException {
		int ch = this.read();
		Token tok = null;
		switch (ch) {
		case T_LPAREN:
			return this.processParen();
		case T_LPAREN2:
			return this.processParen2(); // '(?:'
		case T_CONDITION:
			return this.processCondition(); // '(?('
		case T_MODIFIERS:
			return this.processModifiers(); // (?modifiers ... )
		case T_INDEPENDENT:
			return this.processIndependent();
		case T_DOT:
			this.next(); // Skips '.'
			tok = Token.token_dot;
			break;

		/**
		 * char-class ::= '[' ( '^'? range ','?)+ ']' range ::= '\d' | '\w' |
		 * '\s' | category-block | range-char | range-char '-' range-char
		 * range-char ::= '\[' | '\]' | '\\' | '\' [,-efnrtv] | bmp-code |
		 * character-2 bmp-char ::= '\' 'u' [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F]
		 * [0-9a-fA-F]
		 */
		case T_LBRACKET:
			return this.parseCharacterClass(true);
		case T_SET_OPERATIONS:
			return this.parseSetOperations();

		case T_BACKSOLIDUS:
			switch (this.chardata) {
			case 'd':
			case 'D':
			case 'w':
			case 'W':
			case 's':
			case 'S':
				tok = this.getTokenForShorthand(this.chardata);
				this.next();
				return tok;

			case 'e':
			case 'f':
			case 'n':
			case 'r':
			case 't':
			case 'u':
			case 'v':
			case 'x': {
				int ch2 = this.decodeEscaped();
				if (ch2 < 0x10000) {
					tok = Token.createChar(ch2);
				} else {
					tok = Token.createString(REUtil.decomposeToSurrogates(ch2));
				}
			}
				break;

			case 'c':
				return this.processBacksolidus_c();
			case 'C':
				return this.processBacksolidus_C();
			case 'i':
				return this.processBacksolidus_i();
			case 'I':
				return this.processBacksolidus_I();
			case 'g':
				return this.processBacksolidus_g();
			case 'X':
				return this.processBacksolidus_X();
			case '1':
			case '2':
			case '3':
			case '4':
			case '5':
			case '6':
			case '7':
			case '8':
			case '9':
				return this.processBackreference();

			case 'P':
			case 'p':
				int pstart = this.offset;
				tok = processBacksolidus_pP(this.chardata);
				if (tok == null)
					throw this.ex("parser.atom.5", pstart);
				break;

			default:
				tok = Token.createChar(this.chardata);
			}
			this.next();
			break;

		case T_CHAR:
			if (this.chardata == ']' || this.chardata == '{'
					|| this.chardata == '}')
				throw this.ex("parser.atom.4", this.offset - 1);
			tok = Token.createChar(this.chardata);
			int high = this.chardata;
			this.next();
			if (REUtil.isHighSurrogate(high) && this.read() == T_CHAR
					&& REUtil.isLowSurrogate(this.chardata)) {
				char[] sur = new char[2];
				sur[0] = (char) high;
				sur[1] = (char) this.chardata;
				tok = Token.createParen(Token.createString(new String(sur)), 0);
				this.next();
			}
			break;

		default:
			throw this.ex("parser.atom.4", this.offset - 1);
		}
		return tok;
	}
891232
private static Locale parseLocale(final String str) {
        if (isISO639LanguageCode(str)) {
            return new Locale(str);
        }

        final String[] segments = str.split("_", -1);
        final String language = segments[0];
        if (segments.length == 2) {
            final String country = segments[1];
            if (isISO639LanguageCode(language) && isISO3166CountryCode(country) ||
                    isNumericAreaCode(country)) {
                return new Locale(language, country);
            }
        } else if (segments.length == 3) {
            final String country = segments[1];
            final String variant = segments[2];
            if (isISO639LanguageCode(language) &&
                    (country.length() == 0 || isISO3166CountryCode(country) || isNumericAreaCode(country)) &&
                    variant.length() > 0) {
                return new Locale(language, country, variant);
            }
        }
        throw new IllegalArgumentException("Invalid locale format: " + str);
    }
51556
private NumberFormat createParser(Locale loc) throws JspException {
        NumberFormat parser = null;

        if ((type == null) || NUMBER.equalsIgnoreCase(type)) {
            parser = NumberFormat.getNumberInstance(loc);
        } else if (CURRENCY.equalsIgnoreCase(type)) {
            parser = NumberFormat.getCurrencyInstance(loc);
        } else if (PERCENT.equalsIgnoreCase(type)) {
            parser = NumberFormat.getPercentInstance(loc);
        } else {
            throw new JspException(
                    Resources.getMessage("PARSE_NUMBER_INVALID_TYPE",
                            type));
        }

        return parser;
    }
1049199
float  parseNumber(String input, int startpos, int len)
   {
      boolean  isNegative = false;
      long     significand = 0;
      int      numDigits = 0;
      int      numLeadingZeroes = 0;
      int      numTrailingZeroes = 0;
      boolean  decimalSeen = false;
      int      sigStart;
      int      decimalPos = 0;
      int      exponent;

      long     TOO_BIG = Long.MAX_VALUE / 10;

      pos = startpos;

      if (pos >= len)
        return Float.NaN;  // String is empty - no number found

      char  ch = input.charAt(pos);
      switch (ch) {
         case '-': isNegative = true;
                   // fall through
         case '+': pos++;
      }

      sigStart = pos;

      while (pos < len)
      {
         ch = input.charAt(pos);
         if (ch == '0')
         {
            if (numDigits == 0) {
               numLeadingZeroes++;
            } else {
               // We potentially skip trailing zeroes. Keep count for now.
               numTrailingZeroes++;
            }
         }
         else if (ch >= '1' && ch <= '9')
         {
            // Multiply any skipped zeroes into buffer
            numDigits += numTrailingZeroes;
            while (numTrailingZeroes > 0) {
               if (significand > TOO_BIG) {
                  //Log.e("Number is too large");
                  return Float.NaN;
               }
               significand *= 10;
               numTrailingZeroes--;
            }

            if (significand > TOO_BIG) {
               // We will overflow if we continue...
               //Log.e("Number is too large");
               return Float.NaN;
            }
            significand = significand * 10 + ((int)ch - (int)'0');
            numDigits++;
            
            if (significand < 0)
               return Float.NaN;  // overflowed from +ve to -ve
         }
         else if (ch == '.')
         {
            if (decimalSeen) {
               // Stop parsing here.  We may be looking at a new number.
               break;
            }
            decimalPos = pos - sigStart;
            decimalSeen = true;
         }
         else
            break;
         pos++;
      }

      if (decimalSeen && pos == (decimalPos + 1)) {
         // No digits following decimal point (eg. "1.")
         //Log.e("Missing fraction part of number");
         return Float.NaN;
      }

      // Have we seen anything number-ish at all so far?
      if (numDigits == 0) {
         if (numLeadingZeroes == 0) {
            //Log.e("Number not found");
            return Float.NaN;
         }
         // Leading zeroes have been seen though, so we
         // treat that as a '0'.
         numDigits = 1;
      }

      if (decimalSeen) {
         exponent = decimalPos - numLeadingZeroes - numDigits;
      } else {
         exponent = numTrailingZeroes;
      }

      // Now look for exponent
      if (pos < len)
      {
         ch = input.charAt(pos);
         if (ch == 'E' || ch == 'e')
         {
            boolean  expIsNegative = false;
            int      expVal = 0;
            boolean  abortExponent = false;

            pos++;
            if (pos == len) {
               // Incomplete exponent.
               //Log.e("Incomplete exponent of number");
               return Float.NaN;
            }

            switch (input.charAt(pos)) {
               case '-': expIsNegative = true;
                  // fall through
               case '+': pos++;
                  break;
               case '0': case '1': case '2': case '3': case '4':
               case '5': case '6': case '7': case '8': case '9':
                   break; // acceptable next char
               default:
                  // any other character is a failure, ie no exponent.
                  // Could be something legal like "em" though.
                  abortExponent = true;
                  pos--;  // reset pos to position of 'E'/'e'
            }

            if (!abortExponent)
            {
               int  expStart = pos;

               while (pos < len)
               {
                  ch = input.charAt(pos);
                  if (ch >= '0' && ch <= '9')
                  {
                     if (expVal > TOO_BIG) {
                        // We will overflow if we continue...
                        //Log.e("Exponent of number is too large");
                        return Float.NaN;
                     }
                     expVal = expVal * 10 + ((int)ch - (int)'0');
                     pos++;
                  }
                  else
                     break;
               }

               // Check that at least some exponent digits were read
               if (pos == expStart) {
                  //Log.e(""Incomplete exponent of number"");
                  return Float.NaN;
               }

               if (expIsNegative)
                  exponent -= expVal;
               else
                  exponent += expVal;
            }
         }
      }

      // Quick check to eliminate huge exponents.
      // Biggest float is (2 - 2^23) . 2^127 ~== 3.4e38
      // Biggest negative float is 2^-149 ~== 1.4e-45
      // Some numbers that will overflow will get through the scan
      // and be returned as 'valid', yet fail when value() is called.
      // However they will be very rare and not worth slowing down
      // the parse for.
      if ((exponent + numDigits) > 39 || (exponent + numDigits) < -44)
         return Float.NaN;

      float  f = (float) significand;

      if (significand != 0)
      {
         // Do exponents > 0
         if (exponent > 0)
         {
            f *= positivePowersOf10[exponent];
         }
         else if (exponent < 0)
         {
            // Some valid numbers can have an exponent greater than the max (ie. < -38)
            // for a float.  For example, significand=123, exponent=-40
            // If that's the case, we need to apply the exponent in two steps.
            if (exponent < -38) {
               // Long.MAX_VALUE is 19 digits, so taking 20 off the exponent should be enough. 
               f *= 1e-20;
               exponent += 20;
            }
            // Do exponents < 0
            f *= negativePowersOf10[-exponent];
         }
      }

      return (isNegative) ? -f : f;
   }
185045
private static Locale getLocaleFromString(String localeStr)
        throws IllegalArgumentException {
        // length must be at least 2.
        if (null == localeStr || localeStr.length() < 2) {
            throw new IllegalArgumentException("Illegal locale String: " +
                                               localeStr);
        }

        Locale result = null;
        String lang = null;
        String country = null;
        String variant = null;
        char[] seps = {
            '-',
            '_'
        };
        int inputLength = localeStr.length();
        int i = 0;
        int j = 0;

        // to have a language, the length must be >= 2
        if ((inputLength >= 2) &&
            ((i = indexOfSet(localeStr, seps, 0)) == -1)) {
            // we have only Language, no country or variant
            if (2 != localeStr.length()) {
                throw new
                    IllegalArgumentException("Illegal locale String: " +
                                             localeStr);
            }
            lang = localeStr.toLowerCase();
        }

        // we have a separator, it must be either '-' or '_'
        if (i != -1) {
            lang = localeStr.substring(0, i);
            // look for the country sep.
            // to have a country, the length must be >= 5
            if ((inputLength >= 5) &&
                (-1 == (j = indexOfSet(localeStr, seps, i + 1)))) {
                // no further separators, length must be 5
                if (inputLength != 5) {
                    throw new
                        IllegalArgumentException("Illegal locale String: " +
                                                 localeStr);
                }
                country = localeStr.substring(i + 1);
            }
            if (j != -1) {
                country = localeStr.substring(i + 1, j);
                // if we have enough separators for language, locale,
                // and variant, the length must be >= 8.
                if (inputLength >= 8) {
                    variant = localeStr.substring(j + 1);
                } else {
                    throw new
                        IllegalArgumentException("Illegal locale String: " +
                                                 localeStr);
                }
            }
        }
        if (variant != null && country != null && lang != null) {
            result = new Locale(lang, country, variant);
        } else if (lang != null && country != null) {
            result = new Locale(lang, country);
        } else if (lang != null) {
            result = new Locale(lang, "");
        }
        return result;
    }
1232281
public static Number createNumber(String str) throws ParseException
    {
        try
        {
            if (str.indexOf('.') != -1)
            {
                return Double.valueOf(str);
            }
            return Long.valueOf(str);
        }
        catch (NumberFormatException e)
        {
            throw new ParseException(e.getMessage());
        }
    }
630761
def _convert_localized_value(value: LocalizedValue) -> LocalizedIntegerValue:
        """"""

        integer_values = {}
        for lang_code, _ in settings.LANGUAGES:
            local_value = value.get(lang_code, None)
            if local_value is None or local_value.strip() == '':
                local_value = None

            try:
                integer_values[lang_code] = int(local_value)
            except (ValueError, TypeError):
                integer_values[lang_code] = None

        return LocalizedIntegerValue(integer_values)
47537
public int read_int() throws OtpErlangDecodeException {
        final long l = this.read_long(false);
        final int i = (int) l;

        if (l != i) {
            throw new OtpErlangDecodeException("Value does not fit in int: "
                    + l);
        }

        return i;
    }
403664
public function parse(string $value)
    {
        if (false === \preg_match('//u', $value)) {
            throw new ParseException('The YAML value does not appear to be valid UTF-8.', -1, null, $this->filename);
        }

        $this->refs = [];

        $data = null;

        try {
            $data = $this->doParse($value);
        } finally {
            $this->lines = [];
            $this->currentLine = '';
            $this->refs = [];
            $this->skippedLineNumbers = [];
            $this->locallySkippedLineNumbers = [];
        }

        return $data;
    }
985061
public static BigDecimal parsePrettyString(String numberStr) throws ParseException {
		return new BigDecimal(PRETTY_FORMAT.get().parse(numberStr).doubleValue());
	}