Here you can find the source of roundBigDecimal(Number value, double precision)
public static Number roundBigDecimal(Number value, double precision)
//package com.java2s; /******************************************************************************* * Copyright (c) 2010-2015 BSI Business Systems Integration AG. * 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:// w w w.ja v a 2 s . c o m * BSI Business Systems Integration AG - initial API and implementation ******************************************************************************/ import java.math.BigDecimal; public class Main { /** * rounding with big decimal precision */ public static Number roundBigDecimal(Number value, double precision) { if (value != null) { BigDecimal val = value instanceof BigDecimal ? (BigDecimal) value : new BigDecimal(value.toString()); BigDecimal prec = BigDecimal.valueOf(precision); return val.divide(prec, BigDecimal.ROUND_HALF_EVEN).setScale(0, BigDecimal.ROUND_HALF_EVEN) .multiply(prec); } return null; } }