Java Double Number Create toDouble(Object o)

Here you can find the source of toDouble(Object o)

Description

Attempts to cast an arbitrary object to a Double.

License

Open Source License

Exception

Parameter Description
NullPointerException when o is null
NumberFormatException when the cast fails

Declaration

public static Double toDouble(Object o) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * This file is part of OpenNMS(R).//from  w  w w .  ja  va  2  s  .  co  m
 *
 * Copyright (C) 2010-2015 The OpenNMS Group, Inc.
 * OpenNMS(R) is Copyright (C) 1999-2015 The OpenNMS Group, Inc.
 *
 * OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.
 *
 * OpenNMS(R) is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published
 * by the Free Software Foundation, either version 3 of the License,
 * or (at your option) any later version.
 *
 * OpenNMS(R) 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 Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with OpenNMS(R).  If not, see:
 *      http://www.gnu.org/licenses/
 *
 * For more information contact:
 *     OpenNMS(R) Licensing <license@opennms.org>
 *     http://www.opennms.org/
 *     http://www.opennms.com/
 *******************************************************************************/

public class Main {
    /**
     * Attempts to cast an arbitrary object to a Double.
     *
     * @throws NullPointerException when o is null
     * @throws NumberFormatException when the cast fails
     */
    public static Double toDouble(Object o) {
        if (o instanceof Double) {
            return (Double) o;
        } else {
            // Simple way of casting integers, floats and longs
            return Double.valueOf(o.toString());
        }
    }
}

Related

  1. toDouble(Object number)
  2. toDouble(Object o)
  3. toDouble(Object o)
  4. toDouble(Object o)
  5. toDouble(Object o)
  6. toDouble(Object o)
  7. toDouble(Object ob, Double defaultDouble)
  8. toDouble(Object obj)
  9. toDouble(Object obj)