Java Double Number Round round(double value)

Here you can find the source of round(double value)

Description

round

License

Open Source License

Declaration

public static double round(double value) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2000, 2009 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors://from w w  w . j a  v  a2s .co m
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

public class Main {
    /**
     * @deprecated
     */
    public static double round(double value) {
        return Math.round(value * 10000) / 10000.0;
    }

    /**
     * @deprecated
     */
    public static double round(double value, int precision) {
        if (precision < 0) {
            throw new IllegalArgumentException("Should have a precision at least greater than 0!");
        }
        if (precision == 0)
            return (long) Math.floor(value);
        double factor = 10;
        int n = 1;
        while (n++ < precision)
            factor *= 10;
        return Math.round(value * factor) / factor;
    }
}

Related

  1. round(double valor)
  2. round(double value)
  3. round(double value)
  4. round(double value)
  5. round(double value)
  6. round(double value)
  7. round(double value, double decimalplaces)
  8. round(double value, double factor)
  9. round(double value, double increment)