Java Parse Double parseDouble(Object input)

Here you can find the source of parseDouble(Object input)

Description

DOC Zqin Comment method "parseDouble".

License

Open Source License

Parameter

Parameter Description
input the object that was parsed.

Return

the Double object represents this input

Declaration

public static Double parseDouble(Object input) 

Method Source Code

//package com.java2s;
// %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt

import java.text.DecimalFormat;
import java.text.ParseException;
import java.util.Locale;

public class Main {
    /**//from   w  ww  .  ja  va 2s .c  o  m
     * DOC Zqin Comment method "parseDouble".
     * 
     * @param input the object that was parsed.
     * @return the Double object represents this input
     */
    public static Double parseDouble(Object input) {
        if (input != null) {
            // MOD yyi 2010-04-09 12483 Locale.getDefault() to Locale.US
            DecimalFormat format = (DecimalFormat) DecimalFormat.getInstance(Locale.US);
            try {
                Number number = format.parse(input.toString());
                return number.doubleValue();
            } catch (ParseException e) {
                return Double.NaN;
            }

        }

        return null;
    }
}

Related

  1. parseDouble(Double data)
  2. parseDouble(String d)
  3. parseDouble(String inStr)
  4. parseDouble(String s, Locale locale)
  5. parseDouble(String str)