Java Parse Double parseDouble(String s, Locale locale)

Here you can find the source of parseDouble(String s, Locale locale)

Description

Parse a numeric string using the specified locale.

License

LGPL

Parameter

Parameter Description
s the string to parse.
locale the locale to use for numeric conversion.

Return

the double value. May be NaN if s is null, empty, or unparseable

Declaration

public static double parseDouble(String s, Locale locale) 

Method Source Code

//package com.java2s;
/* /*from  www. j  ava2  s.  c om*/
 * (C) Copyright 2015-2016 by MSDK Development Team
 *
 * This software is dual-licensed under either
 *
 * (a) the terms of the GNU Lesser General Public License version 2.1
 * as published by the Free Software Foundation
 *
 * or (per the licensee's choosing)
 *
 * (b) the terms of the Eclipse Public License v1.0 as published by
 * the Eclipse Foundation.
 */

import java.text.NumberFormat;
import java.text.ParseException;

import java.util.Locale;

public class Main {
    /**
     * Parse a numeric string using the specified locale. When a ParseException
     * is caught, the method returns Double.NaN.
     *
     * @param s
     *            the string to parse.
     * @param locale
     *            the locale to use for numeric conversion.
     * @return the double value. May be NaN if s is null, empty, or unparseable
     */
    public static double parseDouble(String s, Locale locale) {
        if (s == null || s.isEmpty()) {
            return Double.NaN;
        }
        try {
            return NumberFormat.getNumberInstance(locale).parse(s).doubleValue();
        } catch (ParseException ex) {
            try {
                return NumberFormat.getNumberInstance(Locale.US).parse(s).doubleValue();
            } catch (ParseException ex1) {
                return Double.NaN;
            }
        }
    }
}

Related

  1. parseDouble(Double data)
  2. parseDouble(Object input)
  3. parseDouble(String d)
  4. parseDouble(String inStr)
  5. parseDouble(String str)
  6. parseDouble(String str)
  7. parseDouble(String stringValue)
  8. parseDouble(String value)