Java Double Number Round round(double num, int decimal)

Here you can find the source of round(double num, int decimal)

Description

Round-off double to given number of decimal places.

License

Open Source License

Parameter

Parameter Description
num number to round
decimal decimal places

Return

rounded number

Declaration

public static double round(double num, int decimal) 

Method Source Code

//package com.java2s;
// Refer to LICENSE for terms and conditions of use.

public class Main {
    /**/*  ww  w.j  a  va2s.  co m*/
     * Round-off double to given number of decimal places.
     *
     * @param num number to round
     * @param decimal decimal places
     * @return rounded number
     */
    public static double round(double num, int decimal) {
        double factor = Math.pow(10, decimal);
        return Math.rint(num * factor) / factor;
    }
}

Related

  1. round(double n)
  2. round(double n, double nd)
  3. round(Double num)
  4. round(double num)
  5. round(double num, int bit)
  6. round(double num, int numDecs, boolean rawFactor)
  7. round(double num, int precision)
  8. round(double number)
  9. round(double number, double multiplier)