Here you can find the source of round(double number, int digit)
Parameter | Description |
---|---|
number | input number |
digit | specified digits |
public static double round(double number, int digit)
//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); } }