Here you can find the source of round(final double x, final int digits)
Parameter | Description |
---|---|
x | the double to be rounded to the specified digits after period |
digits | the number of digits to be rounded up after period |
public static double round(final double x, final int digits)
//package com.java2s; /*/*w ww .j ava 2 s .c o m*/ * JCAT - TAC Market Design Competition Platform * Copyright (C) 2006-2010 Jinzhong Niu, Kai Cai * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU General Public License for more details. */ public class Main { /** * rounds up a double up to the specified number of digits after period. * * @param x * the double to be rounded to the specified digits after period * @param digits * the number of digits to be rounded up after period * @return the rouned-up double */ public static double round(final double x, final int digits) { final double d = Math.pow(10, digits); return Math.round(x * d) / d; } }