Java Double Number Create toDouble(String value)

Here you can find the source of toDouble(String value)

Description

Extends the Double#valueOf(String) method, in removing the leading and trailing whitespace.

License

Open Source License

Parameter

Parameter Description
value A string representing a double value.

Exception

Parameter Description
NumberFormatException if the string can't be parsed as an double value.

Return

A double representation of the given string, or NaN if the given string is null.

Declaration

public static double toDouble(String value) throws NumberFormatException 

Method Source Code

//package com.java2s;
/*/* w  ww .  j  a v a2s.  c  om*/
 *    Geotoolkit - An Open Source Java GIS Toolkit
 *    http://www.geotoolkit.org
 *
 *    (C) 2008 - 2010, Geomatys
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License as published by the Free Software Foundation; either
 *    version 2.1 of the License, or (at your option) any later version.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 */

public class Main {
    /**
     * Extends the {@link Double#valueOf(String)} method, in removing the leading
     * and trailing whitespace.
     *
     * @param value A string representing a double value.
     * @return A double representation of the given string, or {@code NaN} if the
     *         given string is null.
     * @throws NumberFormatException if the string can't be parsed as an double value.
     */
    public static double toDouble(String value) throws NumberFormatException {
        if (value == null) {
            return Double.NaN;
        }
        value = value.trim();
        return Double.parseDouble(value);
    }
}

Related

  1. ToDouble(String string)
  2. toDouble(String v, double def)
  3. toDouble(String val)
  4. toDouble(String value)
  5. toDouble(String value)
  6. toDouble(String value)
  7. toDouble(String value, double defaultValue)
  8. toDouble(String value, double defaultValue)
  9. toDouble(String value, Double defaultValue)