Java Number Round RoundUp(final T number)

Here you can find the source of RoundUp(final T number)

Description

Returns a long number by round up with specify number.
Returns 0 if number == null.
e.g: average is 3.5, then return 4.

License

Apache License

Parameter

Parameter Description
number number to be handled.

Return

a long number by round up with specify number.

Declaration

public static <T extends Number> long RoundUp(final T number) 

Method Source Code

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

public class Main {
    /**/*from  w  ww  . j  a va 2  s .  c  o m*/
     * Returns a long number by round up with specify number.<br>
     * Returns 0 if number == null.<br>
     * e.g: average is 3.5, then return 4.
     * 
     * @param number
     *            number to be handled.
     * @return a long number by round up with specify number.
     */
    public static <T extends Number> long RoundUp(final T number) {

        if (number == null) {
            return 0;
        }
        double value = number.doubleValue();
        if (value % 1 == 0) {
            return (long) value;
        } else {
            return (long) (value + 1);
        }
    }
}

Related

  1. roundUp(double n, int precision)
  2. roundUp(double val)
  3. roundUp(double val)
  4. roundUp(final double val)
  5. roundUp(final int number, final int base)
  6. roundUp(int capacity)
  7. roundUp(int dividend, int divisor)
  8. roundUp(int groupSize, int globalSize)
  9. roundUp(int groupSize, int globalSize)