Here you can find the source of roundNearest(double v, double target)
public static double roundNearest(double v, double target)
//package com.java2s; //License from project: Apache License public class Main { /**//from w w w. ja va2s . c om * Rounds a value to the nearest multiple of a target. */ public static double roundNearest(double v, double target) { target = Math.abs(target); if (v >= 0) { return target * Math.floor((v + 0.5f * target) / target); } else { return target * Math.ceil((v - 0.5f * target) / target); } } }