Here you can find the source of round(double num, int decimal)
Parameter | Description |
---|---|
num | number to round |
decimal | decimal places |
public static double round(double num, int decimal)
//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; } }