Here you can find the source of roundDoubleAsBigDecimal(double d, int numberOfDecimals)
Parameter | Description |
---|---|
d | the double |
numberOfDecimals | the number of decimals |
public static BigDecimal roundDoubleAsBigDecimal(double d, int numberOfDecimals)
//package com.java2s; //License from project: Apache License import java.math.BigDecimal; public class Main { /**//from w w w .j a va 2s. co m * Rounds a double with the given number of decimals and returns a * BigDecimal. * * @param d the double * @param numberOfDecimals the number of decimals * @return the rounded BigDecimal */ public static BigDecimal roundDoubleAsBigDecimal(double d, int numberOfDecimals) { BigDecimal bigDecimal = new BigDecimal(d).setScale(numberOfDecimals, BigDecimal.ROUND_HALF_UP); return bigDecimal; } }