Java Double Number Parse tryParseDoubleValue(String s, double[] result)

Here you can find the source of tryParseDoubleValue(String s, double[] result)

Description

Try parse integer value from a string value

License

Apache License

Parameter

Parameter Description
s the string value
result the result wrapped as an array of integers

Return

true, if successful

Declaration

public static boolean tryParseDoubleValue(String s, double[] result) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.text.NumberFormat;
import java.text.ParsePosition;

public class Main {
    /**/*from   w w  w  .  jav  a  2s . c om*/
     * Try parse integer value from a string value
     *
     * @param s the string value
     * @param result the result wrapped as an array of integers
     * @return true, if successful
     */
    public static boolean tryParseDoubleValue(String s, double[] result) {
        NumberFormat format = NumberFormat.getNumberInstance();
        ParsePosition position = new ParsePosition(0);
        Object parsedValue = format.parseObject(s, position);

        if (position.getErrorIndex() > -1) {
            return false;
        }

        if (position.getIndex() < s.length()) {
            return false;
        }

        if (parsedValue instanceof Double) {
            result[0] = ((Double) parsedValue).doubleValue();
        } else if (parsedValue instanceof Long) {
            result[0] = ((Long) parsedValue).doubleValue();
        }
        return true;
    }
}

Related

  1. toDouble(final Object o, final String pattern)
  2. toDouble(Locale locale, String value)