Java Number Round roundUp(int number, int interval)

Here you can find the source of roundUp(int number, int interval)

Description

Rounds the first parameter up to the next interval of the second parameter.

License

LGPL

Declaration

public static int roundUp(int number, int interval) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

public class Main {
    /**//from w  w w.  ja  v a 2  s.  c  om
     * Rounds the first parameter up to the next interval of the second parameter.
     *  
     * For instance, {@code roundUp(1, 4)} returns 4; {@code roundUp(0, 4)} returns 0; and {@code roundUp(4, 4)} returns
     * 4.
     */
    public static int roundUp(int number, int interval) {
        if (interval == 0) {
            return 0;
        } else if (number == 0) {
            return interval;
        } else {
            if (number < 0) {
                interval *= -1;
            }

            int i = number % interval;
            return i == 0 ? number : number + interval - i;
        }
    }
}

Related

  1. roundUp(int groupSize, int globalSize)
  2. roundUp(int i, int snap)
  3. roundUp(int n, int nearestMultiple)
  4. roundUp(int ndigits)
  5. roundUp(int num, int divisor)
  6. roundUp(int p_154354_0_, int p_154354_1_)
  7. roundUp(int v, int quant)
  8. roundUp(int val, int shift)
  9. roundUp(int val, int to)