Here you can find the source of doubleToBigDecimal(double dd)
public static BigDecimal doubleToBigDecimal(double dd)
//package com.java2s; //License from project: Apache License import java.math.BigDecimal; public class Main { public static final int SCALE = 4; public static BigDecimal doubleToBigDecimal(double dd) { BigDecimal bd;//w w w.ja v a 2 s . co m try { bd = BigDecimal.valueOf(dd).setScale(SCALE, BigDecimal.ROUND_HALF_UP); } catch (Exception e) { bd = BigDecimal.valueOf(0d); } return bd; } public static BigDecimal doubleToBigDecimal(double dd, int scale) { BigDecimal bd; try { bd = BigDecimal.valueOf(dd).setScale(scale, BigDecimal.ROUND_HALF_UP); } catch (Exception e) { bd = BigDecimal.valueOf(0d); } return bd; } }