Java Double Number Round round(final double num)

Here you can find the source of round(final double num)

Description

Round given number.

License

Open Source License

Parameter

Parameter Description
num number to round.

Return

rounded number.

Declaration

public static int round(final double num) 

Method Source Code

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

public class Main {
    /**// w w w  .j a  va 2s  .  c o  m
     * Round given number.
     *
     * @param num number to round.
     *
     * @return rounded number.
     *
     * @see Math#round(double)
     */
    public static int round(final double num) {
        return floor(num + 0.5d);
    }

    /**
     * Round down given number.
     *
     * @param num number to round down.
     *
     * @return rounded number.
     *
     * @see Math#round(double)
     */
    public static int floor(final double num) {
        final int floor = (int) num;
        return (floor == num) ? floor : ((num > 0) ? floor : (floor - 1));
    }

    /**
     * Round down given number.
     *
     * @param num number to round down.
     *
     * @return rounded number.
     *
     * @see Math#round(double)
     */
    public static int floor(final float num) {
        final int floor = (int) num;
        return (floor == num) ? floor : ((num > 0) ? floor : (floor - 1));
    }
}

Related

  1. round(double x, int places)
  2. round(double zahl, int stellen)
  3. round(double[] arr)
  4. round(double[] array, int decimals)
  5. round(double[][] data)
  6. round(final double num, final int prec)
  7. round(final double numberToRound, final int decimalPlaces)
  8. round(final double v)
  9. round(final double val, final int decimalPlaces)