List of utility methods to do Parse Number
Number | parseNum(String numStr) parse Num return NumberFormat.getInstance().parse(numStr);
|
Object | parseNumber(CharacterIterator it) parse Number StringBuffer buffer = new StringBuffer(); char c = it.current(); while (Character.isDigit(c) || c == '-' || c == '+' || c == '.' || c == 'e' || c == 'E') { buffer.append(c); c = it.next(); try { return new BigDecimal(buffer.toString()); ... |
Number | parseNumber(final String source, final String conversionPattern) parse Number DecimalFormat df = DECIMAL_FORMAT.get();
df.applyPattern(conversionPattern);
return df.parse(source);
|
double | parseNumber(String number) Parses a string with the default locale and returns the corresponding number return parseNumber(number, Locale.getDefault());
|
double | parseNumber(String number) parse Number synchronized (NUMBER_PARSE) { return NUMBER_PARSE.parse(number.trim()).doubleValue(); |
Number | parseNumber(String s) parse Number try { return NumberFormat.getInstance().parse(s); } catch (ParseException e) { throw new RuntimeException("Could not parse " + s + " to number", e); |
Number | parseNumber(String text, Class targetClass) Parse the given text into a number instance of the given target class, using the corresponding default decode methods.
String trimmed = text.trim(); if (targetClass.equals(Byte.class)) { return Byte.decode(trimmed); } else if (targetClass.equals(Short.class)) { return Short.decode(trimmed); } else if (targetClass.equals(Integer.class)) { return Integer.decode(trimmed); } else if (targetClass.equals(Long.class)) { ... |
Number | parseNumber(String text, Class targetClass, NumberFormat numberFormat) Parse the given text into a number instance of the given target class, using the given NumberFormat. if (numberFormat != null) { DecimalFormat decimalFormat = null; boolean resetBigDecimal = false; if (numberFormat instanceof DecimalFormat) { decimalFormat = (DecimalFormat) numberFormat; if (BigDecimal.class.equals(targetClass) && !decimalFormat.isParseBigDecimal()) { decimalFormat.setParseBigDecimal(true); resetBigDecimal = true; ... |
T | parseNumber(String text, Class Parse the given text into a Number instance of the given target class, using the corresponding decode / valueOf method. Objects.requireNonNull(text, "Text must not be null"); Objects.requireNonNull(targetClass, "Target class must not be null"); String trimmed = text.trim(); if (Byte.class == targetClass) { return (T) (isHexNumber(trimmed) ? Byte.decode(trimmed) : Byte.valueOf(trimmed)); } else if (Short.class == targetClass) { return (T) (isHexNumber(trimmed) ? Short.decode(trimmed) : Short.valueOf(trimmed)); } else if (Integer.class == targetClass) { ... |
Number | parseNumeric(String value) parse Numeric try { return Long.parseLong(value); } catch (NumberFormatException nfe) { try { return Double.parseDouble(value); } catch (NumberFormatException nfe2) { try { return NumberFormat.getInstance().parse(value); ... |