Here you can find the source of roundToNearest(int num, int nearest)
Parameter | Description |
---|---|
num | the number i.e. 900 |
nearest | the nearest i.e. 500 |
public static int roundToNearest(int num, int nearest)
//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)); } }