Java Utililty Methods Parse Number

List of utility methods to do Parse Number

Description

The list of methods to do Parse Number are organized into topic(s).

Method

NumberparseNum(String numStr)
parse Num
return NumberFormat.getInstance().parse(numStr);
ObjectparseNumber(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());
...
NumberparseNumber(final String source, final String conversionPattern)
parse Number
DecimalFormat df = DECIMAL_FORMAT.get();
df.applyPattern(conversionPattern);
return df.parse(source);
doubleparseNumber(String number)
Parses a string with the default locale and returns the corresponding number
return parseNumber(number, Locale.getDefault());
doubleparseNumber(String number)
parse Number
synchronized (NUMBER_PARSE) {
    return NUMBER_PARSE.parse(number.trim()).doubleValue();
NumberparseNumber(String s)
parse Number
try {
    return NumberFormat.getInstance().parse(s);
} catch (ParseException e) {
    throw new RuntimeException("Could not parse " + s + " to number", e);
NumberparseNumber(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)) {
...
NumberparseNumber(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;
...
TparseNumber(String text, Class targetClass)
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) {
...
NumberparseNumeric(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);
...