Java Integer Divide divideAndRound(int dividend, int divisor)

Here you can find the source of divideAndRound(int dividend, int divisor)

Description

Perform a division of the input integers, and round to the next integer if the divisor is not a even multiple of the dividend.

License

Open Source License

Parameter

Parameter Description
dividend the number to be divided
divisor the number by which to divide

Return

the result of the division, with possible rounding

Declaration

public static int divideAndRound(int dividend, int divisor) 

Method Source Code

//package com.java2s;
//  it under the terms of the GNU General Public License as published by

public class Main {
    /**//from w  w w .  j  av  a  2  s. c  o m
     * Perform a division of the input integers, and round to the next integer
     * if the divisor is not a even multiple of the dividend.
     *
     * @param dividend  the number to be divided
     * @param divisor   the number by which to divide
     * @return          the result of the division, with possible rounding
     */
    public static int divideAndRound(int dividend, int divisor) {
        int result = 0;

        if (divisor != 0) {
            result = ((dividend % divisor) == 0) ? (dividend / divisor) : ((dividend / divisor) + 1);
        }

        return result;
    }
}

Related

  1. divide(int value, int divideBy)
  2. divide(int x, int y)
  3. Divide(Object in, int val)
  4. divideAndCeil(int a, int b)
  5. divideAndCeil(int dividend, int divisor)
  6. divideAndRoundUp(long dividend, int divisor)
  7. divideRoundUp(int first, int second)
  8. divideStringWithInt(String strDividend, int divisor)
  9. divideToCeil(int numerator, int denominator)