Here you can find the source of roundDownToNearest(double number, double nearest)
public static double roundDownToNearest(double number, double nearest)
//package com.java2s; /**/*from w w w . j a va 2s . c o m*/ * 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 roundDownToNearest(double number, double nearest) { return Math.floor(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; } }