Java BigDecimal Create getBigDecimal(Object value)

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

Description

get Big Decimal

License

Open Source License

Declaration

public static BigDecimal getBigDecimal(Object value) throws Exception 

Method Source Code

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

import java.math.*;

public class Main {
    public static BigDecimal getBigDecimal(Object value) throws Exception {
        // check for NULL
        if (value == null) {
            return null;
        }//from   w ww . jav  a 2  s . com

        try {
            return (new BigDecimal(value.toString().trim()));
        } catch (NumberFormatException ex) {
            throw new Exception("bigdecimal conversion failed. (" + value.toString().trim() + ")");
        }
    }

    public static BigDecimal getBigDecimal(Object value, int scale) throws Exception {
        BigDecimal bDecimal, result;

        // check for NULL
        if (value == null) {
            return (new BigDecimal(0));
        }

        bDecimal = getBigDecimal(value);
        result = bDecimal.setScale(scale);

        return result;
    }
}

Related

  1. getBigDecimal(Number number)
  2. getBigDecimal(Object number)
  3. getBigDecimal(Object o)
  4. getBigDecimal(Object o)
  5. getBigDecimal(Object v, BigDecimal defaultValue)
  6. getBigDecimal(Object value)
  7. getBigDecimal(String aInput)
  8. getBigDecimal(String value)
  9. getBigDecimalArrayFromByteArray(byte[] buf)