Java Double Number Round round(final double x, final int digits)

Here you can find the source of round(final double x, final int digits)

Description

rounds up a double up to the specified number of digits after period.

License

Open Source License

Parameter

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

Return

the rouned-up double

Declaration

public static double round(final double x, final int digits) 

Method Source Code

//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;
    }
}

Related

  1. round(final double val, final int decimalPlaces)
  2. round(final double val, final int decimals)
  3. round(final Double value)
  4. round(final Double value)
  5. round(final double value, final int numDecimals)
  6. round2(double d)
  7. round2(double num)
  8. round2(final double arg)
  9. round2(int a, int preserveDigits)