public static Number sum ( Number n1 , Number n2 ) { Class < ? > type = getComputationType ( n1 , n2 ) ; Number val1 = convertTo ( n1 , type ) ; Number val2 = convertTo ( n2 , type ) ; if ( type == Long . class ) return Long . valueOf ( val1 . longValue ( ) + val2 . longValue ( ) ) ; return new Double ( val1 . doubleValue ( ) + val2 . doubleValue ( ) ) ; }
Sum two numbers