Here you can find the source of toDouble(Object argSource)
Parameter | Description |
---|---|
argSource | a parameter |
public static double toDouble(Object argSource)
//package com.java2s; /**// w w w. j av a 2s . com * Project: JLIB * Version: $Id$ * License: (see below block, or the accompanied COPYING.txt file) **************************************************************************************** LICENSE BEGIN ***** * Copyright (c) 2009-2013, JLIB AUTHORS (see the AUTHORS.txt file for the list of the individuals) * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided * that the following conditions are met: * * 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution. * 3) Neither the names of the organisations involved in the JLIB project, nor the names of their * contributors to the JLIB project may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ****************************************************************************************** LICENSE END ***** * * This file is best viewed with 110 columns. 12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 * * In chronological order * Author(s): * Dejan Lekic , http://dejan.lekic.org * Contributor(s): * - */ public class Main { /** * Use this method to convert any Number object to a double. * * NOTE: This method may become deprecated because user can simply do: * * Number num = (Number) object; // object is an instance of any Number subtype. * double value = num.doubleValue(); * * @param argSource * @return */ public static double toDouble(Object argSource) { double ret = Double.NaN; Class argClass = argSource.getClass(); if (argClass == Byte.class) { Byte val = (Byte) argSource; ret = val.doubleValue(); } if (argClass == Short.class) { Short val = (Short) argSource; ret = val.doubleValue(); } if (argClass == Integer.class) { Integer val = (Integer) argSource; ret = val.doubleValue(); } if (argClass == Long.class) { Long val = (Long) argSource; ret = val.doubleValue(); } if (argClass == Float.class) { Float val = (Float) argSource; ret = val.doubleValue(); } if (argClass == Double.class) { ret = (Double) argSource; } return ret; } }