Java examples for java.lang:double
Round double value
/******************************************************************************* * <copyright> Copyright (c) 2014-2016 Bauhaus Luftfahrt e.V.. 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 </copyright> ******************************************************************************/ //package com.java2s; import java.math.BigDecimal; public class Main { /**//w w w.ja v a 2s. c o m * Round. * * @param value * the value * @param numberOfDigitsAfterDecimalPoint * the number of digits after decimal point * @return the double */ public static double round(double value, int numberOfDigitsAfterDecimalPoint) { BigDecimal bigDecimal = new BigDecimal(value); bigDecimal = bigDecimal.setScale(numberOfDigitsAfterDecimalPoint, BigDecimal.ROUND_HALF_UP); return bigDecimal.doubleValue(); } }