Java Number Round roundToNearest(int num, int nearest)

Here you can find the source of roundToNearest(int num, int nearest)

Description

Rounds the number to the nearest.

License

Open Source License

Parameter

Parameter Description
num the number i.e. 900
nearest the nearest i.e. 500

Declaration

public static int roundToNearest(int num, int nearest) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**/*from  w  w w .j  a v a  2s .  c  o  m*/
     * Rounds the number to the nearest. 900 rounded to nearest 500 is 1000
     * @param num the number i.e. 900
     * @param nearest the nearest i.e. 500
     * @return
     */
    public static int roundToNearest(int num, int nearest) {
        return (int) (nearest * Math.round((double) num / (double) nearest));
    }
}

Related

  1. roundToN(double d, int n)
  2. roundToNDecimalPlaces(final double in, final int n)
  3. roundToNDigits(double d, int n)
  4. roundToNearest(double d)
  5. roundToNearest(double number)
  6. roundToNearestEven(int mantissa, int numOfBitsToRoundOff)
  7. roundToNearestInterval(int i, int j)
  8. roundToNearestK(float v, int k)
  9. roundToNearestMultiple(double number, double multiple)