Java BigDecimal from castToBigDecimal(Object value)

Here you can find the source of castToBigDecimal(Object value)

Description

cast To Big Decimal

License

Open Source License

Declaration

public static BigDecimal castToBigDecimal(Object value) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.math.BigDecimal;
import java.math.BigInteger;

public class Main {
    public static BigDecimal castToBigDecimal(Object value) {
        if (value == null) {
            return null;
        }//ww  w. j a v  a2s  . c  om

        if (value instanceof BigDecimal) {
            return (BigDecimal) value;
        }

        if (value instanceof BigInteger) {
            return new BigDecimal((BigInteger) value);
        }

        String strVal = value.toString();
        if (strVal.length() == 0) {
            return null;
        }

        return new BigDecimal(strVal);
    }
}

Related

  1. bytesToBigDecimal(byte[] buffer)
  2. byteToBigDecimal(byte[] raw)
  3. byteToBigDecimal(byte[] raw)
  4. castBigDecimal(Object o)
  5. convertNumberToBigDecimal(Number aNumber)
  6. doubleArrayToBigDecimalList( double[] array)
  7. doubleToBigDecimal(double amountAsDouble)
  8. doubleToBigDecimal(double dd)