Java Double Number Round round(double n)

Here you can find the source of round(double n)

Description

Round to the nearest integer.
This is different from Math.round() for negative number.

License

Open Source License

Declaration

public static int round(double n) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**//from  w  w  w.j a v a2 s  .c  om
     * Round to the nearest integer.<br>
     * This is different from Math.round() for negative number.
     * i.e., 2.5->3, 2.499->2, -1.499->-1, -1.5-->-2
     */
    public static int round(double n) {
        return (int) ((n > 0 ? 0.5 : -0.5) + n);
    }
}

Related

  1. round(double d, int precision)
  2. Round(double d, int Rpl)
  3. round(double dValue)
  4. round(double input)
  5. round(double input, double step)
  6. round(double n, double nd)
  7. round(Double num)
  8. round(double num)
  9. round(double num, int bit)