Java Double Number Round roundDownToNearest(double number, double nearest)

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

Description

round Down To Nearest

License

Open Source License

Declaration

public static double roundDownToNearest(double number, double nearest) 

Method Source Code

//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;
    }
}

Related

  1. roundDown(int val, int to)
  2. roundDown(long n, long m)
  3. roundDown(long size, long roundBoundary)
  4. roundDown(long val, long delta)
  5. roundDownTo(int a, int quanta)
  6. roundDownToNearestK(float v, int k)
  7. roundDownToPowerOf2(int value)