Java Number Divide divide(Number n1, Number n2)

Here you can find the source of divide(Number n1, Number n2)

Description

divide

License

Open Source License

Declaration

public static Number divide(Number n1, Number n2) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2012 The University of York.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * /*from  ww  w . j a  va 2 s .  com*/
 * Contributors:
 *     Dimitrios Kolovos - initial API and implementation
 ******************************************************************************/

public class Main {
    public static Number divide(Number n1, Number n2) {
        if (n1 instanceof Double || n2 instanceof Double) {
            return n1.doubleValue() / n2.doubleValue();
        } else if (n1 instanceof Float || n2 instanceof Float) {
            return n1.floatValue() / n2.floatValue();
        } else if (n1 instanceof Long || n2 instanceof Long) {
            return n1.longValue() / n2.longValue();
        } else {
            return n1.intValue() / n2.intValue();
        }
    }
}

Related

  1. div(double v1, double v2)
  2. div(double v1, double v2, int scale)
  3. div(long v1, long v2)
  4. div(Object a, Object b)
  5. divide(Number a, Number b, Class cl)
  6. divide(Number n1, Number n2)
  7. divide(Number num1, Number num2)
  8. divide(Number numerator, Number denominator)
  9. divide(Number numerator, Number divisor)