Java Double Number Round roundDown(double a)

Here you can find the source of roundDown(double a)

Description

Returns the closest int to the argument, with ties rounding down.

License

Open Source License

Declaration

public static int roundDown(double a) 

Method Source Code

//package com.java2s;
//License from project: GNU General Public License 

public class Main {
    /** Returns the closest int to the argument, with ties rounding down. */
    public static int roundDown(double a) {
        double r = a % 1;
        if (r < 0)
            r += 1;//from ww  w. jav  a 2 s.  c  om
        return r == 0.5 ? (int) Math.round(a) - 1 : (int) Math.round(a);
    }

    /** Returns the closest int to the argument, with ties rounding down. */
    public static int roundDown(float a) {
        float r = a % 1;
        if (r < 0)
            r += 1;
        return r == 0.5f ? Math.round(a) - 1 : Math.round(a);
    }
}

Related

  1. roundDoubleNicely(double intensity)
  2. roundDoubleTo(double val, int pow)
  3. roundDoubleToInt(final double VALUE)
  4. roundDoubleToPlace(double d, int place)
  5. roundDoubleValue(double value)
  6. roundDown(double amt, double digits)
  7. roundDown(double n)
  8. roundDown(double num)
  9. roundDown(double val, int decimals)