Java Number Round roundToDecimals(double d, int numberOfDecimalPlaces)

Here you can find the source of roundToDecimals(double d, int numberOfDecimalPlaces)

Description

round To Decimals

License

Open Source License

Parameter

Parameter Description
d a parameter
numberOfDecimalPlaces a parameter

Declaration

public static double roundToDecimals(double d, int numberOfDecimalPlaces) 

Method Source Code

//package com.java2s;
/**// ww w .  j a  v a  2  s  .  c o  m
 * ?Copyright (C) 2012
 * by 52 North Initiative for Geospatial Open Source Software GmbH
 *
 * Contact: Andreas Wytzisk
 * 52 North Initiative for Geospatial Open Source Software GmbH
 * Martin-Luther-King-Weg 24
 * 48155 Muenster, Germany
 * info@52north.org
 *
 * This program is free software; you can redistribute and/or modify it under
 * the terms of the GNU General Public License version 2 as published by the
 * Free Software Foundation.
 *
 * This program is distributed WITHOUT ANY WARRANTY; even without the implied
 * WARRANTY OF MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program (see gnu-gpl v2.txt). If not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA or
 * visit the Free Software Foundation web page, http://www.fsf.org.
 */

public class Main {
    /**
     * @param d
     * @param numberOfDecimalPlaces
     * @return
     */
    public static double roundToDecimals(double d, int numberOfDecimalPlaces) {
        int temp = (int) ((d * Math.pow(10, numberOfDecimalPlaces)));
        return (temp / Math.pow(10, numberOfDecimalPlaces));
    }
}

Related

  1. roundToDecentPrecision(double value)
  2. roundToDecimalPlaces(final double val, final int places)
  3. roundToDecimals(double d, int c)
  4. roundToDecimals(double d, int c)
  5. roundToDecimals(double d, int c)
  6. roundToDecimals(double d, int percision)
  7. roundToDecimals(double doubleValue)
  8. roundToDecimals(double input, int places)
  9. roundToDefaultPrecision(final double value)