public static long safeDivide ( long dividend , long divisor , RoundingMode roundingMode ) { if ( dividend == Long . MIN_VALUE && divisor == - 1L ) { throw new ArithmeticException ( "Multiplication overflows a long: " + dividend + " / " + divisor ) ; } BigDecimal dividendBigDecimal = new BigDecimal ( dividend ) ; BigDecimal divisorBigDecimal = new BigDecimal ( divisor ) ; return dividendBigDecimal . divide ( divisorBigDecimal , roundingMode ) . longValue ( ) ; }
Divides the dividend by divisor . Rounding of result occurs as per the roundingMode .