Java Double Number Round roundDouble(double value)

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

Description

This method takes double value as a parameter and rounds it to two decimal points and returns the rounded value.

License

Open Source License

Parameter

Parameter Description
value value to be rounded

Return

double roundedvalue

Declaration

public static double roundDouble(double value) 

Method Source Code

//package com.java2s;
/*//from   w  w w.j ava  2 s . c  o  m
 * @(#)ConversionUtil.java
 *
 * Copyright by ObjectFrontier, Inc.,
 * 12225 Broadleaf Lane, Alpharetta, GA 30005, U.S.A.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information
 * of ObjectFrontier, Inc. You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of
 * the license agreement you entered into with ObjectFrontier.
 */

public class Main {
    /**
     * This method takes double value as a parameter and rounds it to
     * two decimal points and returns the rounded value.
     *
     * @param   value value to be rounded
     * @return  double roundedvalue
     */
    public static double roundDouble(double value) {

        int decimalPlace = 2;
        double power_of_ten = 1;

        while (decimalPlace-- > 0) {
            power_of_ten *= 10.0;
        }

        return Math.round(value * power_of_ten) / power_of_ten;
    }
}

Related

  1. roundDouble(double d, int places)
  2. roundDouble(double num, int precision)
  3. roundDouble(double number, int precision)
  4. roundDouble(double pDouble, int pPlaces)
  5. roundDouble(double val, int precision)
  6. roundDouble(double value, int afterDecimalPoint)
  7. roundDouble3(double r)
  8. roundDoubleDownTo(double value, double steps)
  9. roundDoubleNicely(double intensity)