Java BigDecimal from doubleToBigDecimal(double dd)

Here you can find the source of doubleToBigDecimal(double dd)

Description

double To Big Decimal

License

Apache License

Declaration

public static BigDecimal doubleToBigDecimal(double dd) 

Method Source Code


//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;
    }
}

Related

  1. castBigDecimal(Object o)
  2. castToBigDecimal(Object value)
  3. convertNumberToBigDecimal(Number aNumber)
  4. doubleArrayToBigDecimalList( double[] array)
  5. doubleToBigDecimal(double amountAsDouble)
  6. longToBigDecimal(long amountAsSatoshis)
  7. numberToBigDecimal(Number number)
  8. numberToBigDecimal(Number value)
  9. numberToBigDecimal(Object number)