Java Number Round roundUpToNearest(double number, double nearest)

Here you can find the source of roundUpToNearest(double number, double nearest)

Description

round Up To Nearest

License

Open Source License

Declaration

public static double roundUpToNearest(double number, double nearest) 

Method Source Code

//package com.java2s;
/**//from w ww.j  av a 2s  .  c om
 * NumericImpl contains logic for numeric data. This implementation is referred to YUI's NumericImpl.js which license under
 * BSD License. - http://yuilibrary.com/license/
 * @author jumperchen
 *
 */

public class Main {
    public static double roundUpToNearest(double number, double nearest) {
        return Math.ceil(roundToPrecision(number / nearest, 10)) * nearest;
    }

    public static double roundToPrecision(double number, int precision) {
        double decimalPlaces = Math.pow(10, precision);
        return Math.round(decimalPlaces * number) / decimalPlaces;
    }
}

Related

  1. roundUpTo(long i, long multiple)
  2. roundUpTo100(int n)
  3. roundUpTo8(final long number)
  4. roundUpTo8(long val)
  5. roundUpToMultiple(long val, int factor)
  6. roundUpToNearestEightBytes(long result)
  7. roundUpToNearestPowerOfTwoIfGreaterThanZero(final int value)
  8. roundUpToPowerOf2(int number)
  9. roundUpToPowerOf2(long val)