Java Number Round roundUpTo(double in, double del)

Here you can find the source of roundUpTo(double in, double del)

Description

round in up to the next even multiple of del

License

Apache License

Parameter

Parameter Description
in initial value
del interval

Return

next multiple of del >= in

Declaration

public static double roundUpTo(double in, double del) 

Method Source Code

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

public class Main {
    /**//w  ww .  jav a  2s  .  co  m
     * round in up to the next even multiple of del
     * @param in initial value
     * @param del interval
     * @return next multiple of del >= in
     */
    public static double roundUpTo(double in, double del) {
        int n = (int) (in / del);
        double ret = n * del;
        if (ret == in)
            return (ret);
        return (ret + del);
    }

    /**
     * round in up to the next even multiple of del
     * @param in initial value
     * @param del interval
     * @return next multiple of del >= in
     */
    public static int roundUpTo(int in, int del) {
        int n = (int) (in / del);
        int ret = n * del;
        if (ret == in)
            return (ret);
        return (ret + del);
    }
}

Related

  1. roundUpNumberByUsingMultipleValue(double number, double multiple)
  2. roundUpPOT(int value)
  3. roundUpPow2(int x)
  4. roundUpPower2(int i)
  5. roundUpPower2(int v)
  6. roundUpTo(int a, int quanta)
  7. roundUpTo(long i, long multiple)
  8. roundUpTo100(int n)
  9. roundUpTo8(final long number)