Java Double Number Round round(double number, int digit)

Here you can find the source of round(double number, int digit)

Description

Rounds a number to keep specified digits.

License

LGPL

Parameter

Parameter Description
number input number
digit specified digits

Return

result after rounding

Declaration

public static double round(double number, int digit) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

public class Main {
    /**/*from  w  w  w .  j  ava  2s .  c o m*/
     * Rounds a number to keep specified digits.
     * 
     * The absolute value of input number can't be large than 1E16.
     * 
     * @param number
     *            input number
     * @param digit
     *            specified digits
     * @return result after rounding
     */
    public static double round(double number, int digit) {
        long l = Math.round(number * Math.pow(10, digit));
        return (double) l / Math.pow(10, digit);
    }
}

Related

  1. round(double num, int numDecs, boolean rawFactor)
  2. round(double num, int precision)
  3. round(double number)
  4. round(double number, double multiplier)
  5. round(double number, int decimal)
  6. round(double number, int digits)
  7. round(double number, int places)
  8. round(double number, int places)
  9. round(double number, int precision)