Java Number Multiply multiplyNumbers(Number a, Number b)

Here you can find the source of multiplyNumbers(Number a, Number b)

Description

multiply Numbers

License

Open Source License

Declaration

public static Number multiplyNumbers(Number a, Number b) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static Number multiplyNumbers(Number a, Number b) {
        if (a instanceof Double || b instanceof Double) {
            return Double.valueOf(a.doubleValue() * b.doubleValue());
        } else if (a instanceof Float || b instanceof Float) {
            return Float.valueOf(a.floatValue() * b.floatValue());
        } else if (a instanceof Long || b instanceof Long) {
            return Long.valueOf(a.longValue() * b.longValue());
        } else if (a instanceof Integer || b instanceof Integer) {
            return Integer.valueOf(a.intValue() * b.intValue());
        } else if (a instanceof Short || b instanceof Short) {
            return Short.valueOf((short) (a.shortValue() * b.shortValue()));
        } else {/*ww w.j a va  2s.  com*/
            throw new UnsupportedOperationException("can not multiply " + a + " and " + b);
        }
    }
}

Related

  1. multiply(Number n1, Number n2)
  2. multiply(Number n1, Number n2)
  3. multiply(V1 value1, V2 value2)
  4. multiplyForLong(final Number operand1, final int operand2)
  5. multiplyLongs(Long a, Long b)